
92  ZOJ Monthly, June 2010  E
Xiaoyao likes to play with pictures very much. When he got a picture, he will use rectangle selection tool to select an area ((x_{1}, y_{1}) to (x_{2}, y_{2}), inclusively) and perform these operations:
After several operations, Xiaoyao wonders what value a pixel at specified position is. Could you tell him? Input There are multi cases (no more than 5). Please proceed to the end of input. Each case is like below: The first line contains two integers W and H, indicating the width and height of the picture. W and H are both between 1 and 255, inclusively. Following H lines, each line contains W integers, indicating the value of pixels. The first integer of the first line in these H lines is the value of pixel at (0, 0) and the last integer is the value of pixel at (W1, H1). All these values are between 10^{5} and 10^{5}, inclusively. Then, a line with one integer M(0 <= M <= 10^{5}). Following M lines, each line contains 5 integers: x_{1} y_{1} x_{2} y_{2} op, indicating the selected area and the operation. (0 <= x_{1} <= x_{2} < W, 0 <= y_{1} <= y_{2} < H, 1 <= op <= 5). If op is 1, it means Invert operation. If op is 2, it means Lighten operation. The others follow by analogy. You should follow the order of the input to perform operations. Finally, there is a line with two integers x and y. (0 <= x < W, 0 <= y < H) Your task is to output the value of pixel at (x, y) after performing above operations. Output For each case, output a single line containing one integer which is the value of pixel at (x, y) at last. Sample Input 3 2 1 2 3 4 5 6 2 0 0 1 1 1 1 0 2 1 4 2 1 Sample Output 5 