#include #include #include #include #include int ri() { int n; scanf("%d", &n); return n; } int64_t rs64() { int64_t n; scanf("%" SCNd64, &n); return n; } #define y1 y1_dummy bool tmp0[50000], tmp[50000]; int x1[50000], x2[50000], y1[50000], y2[50000], c[50000]; int64_t h[50000]; int main() { int n = ri(); for (auto &i : h) i = rs64(); for (int i = 0; i < n; i++) x1[i] = ri(), y1[i] = ri(), x2[i] = ri(), y2[i] = ri(), c[i] = ri() - 1; int q = ri(); clock_t r0 = clock(); for (int i = 0; i < q; i++) { memset(tmp, 0, sizeof(tmp)); int x = ri(), y = ri(); for (int j = 0; j < n; j++) tmp0[j] = x1[j] <= x && x < x2[j]; for (int j = 0; j < n; j++) tmp0[j] &= y1[j] <= y && y < y2[j]; for (int j = 0; j < n; j++) if (tmp0[j]) tmp[c[j]] = true; int64_t res = 0; for (int j = 0; j < n; j++) if (tmp[j]) res ^= h[j]; printf("%lld\n", (long long) res); } clock_t r1 = clock(); std::cerr << (double) (r1 - r0) / CLOCKS_PER_SEC << std::endl; return 0; }