import sys def main(): sys.setrecursionlimit(1 << 25) input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 h_list = list(map(int, input[ptr:ptr+N])) ptr += N max_coord = 2 * N + 2 bit = BIT2D(max_coord, max_coord) for _ in range(N): a = int(input[ptr]) b = int(input[ptr+1]) c = int(input[ptr+2]) d = int(input[ptr+3]) e = int(input[ptr+4]) - 1 # converting to 0-based ptr += 5 x1 = a + 1 y1 = b + 1 x2 = c y2 = d v = h_list[e] # Update four corners bit.update(x1, y1, v) bit.update(x1, y2 + 1, v) bit.update(x2 + 1, y1, v) bit.update(x2 + 1, y2 + 1, v) Q = int(input[ptr]) ptr += 1 output = [] for _ in range(Q): p = int(input[ptr]) q = int(input[ptr+1]) ptr += 2 x = p + 1 y = q + 1 res = bit.query(x, y) output.append(str(res)) print('\n'.join(output)) class BIT2D: def __init__(self, max_x, max_y): self.max_x = max_x self.max_y = max_y self.tree = [[0]*(max_y + 2) for _ in range(max_x + 2)] def update(self, x, y, val): while x <= self.max_x: y0 = y while y0 <= self.max_y: self.tree[x][y0] ^= val y0 += y0 & -y0 x += x & -x def query(self, x, y): res = 0 while x > 0: y0 = y while y0 > 0: res ^= self.tree[x][y0] y0 -= y0 & -y0 x -= x & -x return res if __name__ == '__main__': main()