#include #include #include using ull = unsigned long long; using usize = std::size_t; constexpr usize NMAX = 50000; ull h[NMAX]; std::bitset used; usize a[NMAX], b[NMAX], c[NMAX], d[NMAX], e[NMAX]; int main() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false); usize N; std::cin >> N; for (usize i = 0; i < N; i++) { std::cin >> h[i]; } for (usize i = 0; i < N; i++) { std::cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i], e[i]--; } usize Q; std::cin >> Q; for (usize i = 0, p, q; i < Q; i++) { used.reset(); std::cin >> p >> q; ull ans = 0; for (usize j = 0; j < N; j++) { if (a[j] <= p and p < c[j] and b[j] <= q and q < d[j] and not used[e[j]]) { used[e[j]] = true, ans ^= h[e[j]]; } } std::cout << ans << "\n"; } return 0; }