#include <bits/stdc++.h>   using namespace std;   int dx8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dx4[4] = {-1, 0, 1, 0};   int dy8[8] = {0, -1, -1, -1, 0, 1, 1, 1}, dy4[4] = {0, -1, 0, 1};   inline void open(string name) {     freopen((name +  .in ).c_str(),  r , stdin);     freopen((name +  .out ).c_str(),  w , stdout);   }   inline void close() {     fclose(stdin);     fclose(stdout);   }   inline int io() {     register char c;     while (1) {       c = getchar_unlocked();       if (c !=   n  && c !=    ) break;     }     int res = 0, sign = 1;     if (c ==  - )       sign = -1;     else       res = c -  0 ;     while (1) {       c = getchar_unlocked();       if (c ==     || c ==   n  || c == EOF) break;       res = (res << 3) + (res << 1) + c -  0 ;     }     return res * sign;   }   const int N = 100005;   struct Bullet {     int x;     int y;     int idx;     Bullet() {}     bool operator<(Bullet other) const {       if (x == other.x) {         if (y == other.y)           return idx < other.idx;         else           return y < other.y;       } else         return x < other.x;     }   };   Bullet origin[N], arr[N];   struct Node {     vector<pair<int, int> > bullet_list;     vector<int> RMQ;     Node() {       bullet_list.clear();       RMQ.clear();     }     void Build() {       RMQ.resize(4 * bullet_list.size());       Build(1, 0, bullet_list.size() - 1);     }     void Build(int id, int l, int r) {       if (l == r)         RMQ[id] = bullet_list[l].second;       else {         int chld = id << 1, m = (l + r) >> 1;         Build(chld, l, m);         Build(chld + 1, m + 1, r);         RMQ[id] = min(RMQ[chld], RMQ[chld + 1]);       }     }     int Query(int ya, int yb) {       int st =           lower_bound(bullet_list.begin(), bullet_list.end(), make_pair(ya, 0)) -           bullet_list.begin();       int en = upper_bound(bullet_list.begin(), bullet_list.end(),                            make_pair(yb, 1000000000)) -                bullet_list.begin();       en--;       if (st > en)         return 1000000000;       else         return Query(1, 0, bullet_list.size() - 1, st, en);     }     int Query(int id, int l, int r, int x, int y) {       if (x <= l && r <= y)         return RMQ[id];       else {         int chld = (id << 1), m = (l + r) >> 1;         int res = 1000000000;         if (x <= m) res = min(res, Query(chld, l, m, x, y));         if (y > m) res = min(res, Query(chld + 1, m + 1, r, x, y));         return res;       }     }     void Del(int id) {       int ya = origin[id].y;       int st =           lower_bound(bullet_list.begin(), bullet_list.end(), make_pair(ya, id)) -           bullet_list.begin();       Del(1, 0, bullet_list.size() - 1, st);     }     void Del(int id, int l, int r, int x) {       if (l == r) {         RMQ[id] = 1000000000;       } else {         int chld = id << 1, m = (l + r) >> 1;         if (x <= m)           Del(chld, l, m, x);         else           Del(chld + 1, m + 1, r, x);         RMQ[id] = min(RMQ[chld], RMQ[chld + 1]);       }     }   };   Node rtree[4 * N];   vector<int> X;   int n, q;   int ans[N];   void BuildRangeTree(int id, int l, int r) {     if (l == r) {       rtree[id].bullet_list.push_back(make_pair(arr[l].y, arr[l].idx));     } else {       int chld = id << 1, m = (l + r) >> 1;       BuildRangeTree(chld, l, m);       BuildRangeTree(chld + 1, m + 1, r);       int i = 0, j = 0;       while (i < rtree[chld].bullet_list.size() &&              j < rtree[chld + 1].bullet_list.size()) {         if (rtree[chld].bullet_list[i] < rtree[chld + 1].bullet_list[j])           rtree[id].bullet_list.push_back(rtree[chld].bullet_list[i++]);         else           rtree[id].bullet_list.push_back(rtree[chld + 1].bullet_list[j++]);       }       while (i < rtree[chld].bullet_list.size())         rtree[id].bullet_list.push_back(rtree[chld].bullet_list[i++]);       while (j < rtree[chld + 1].bullet_list.size())         rtree[id].bullet_list.push_back(rtree[chld + 1].bullet_list[j++]);     }     rtree[id].Build();   }   void UpdateRangeTree(int pos) {     int idpos = lower_bound(arr, arr + q, origin[pos]) - arr;     int id = 1, l = 0, r = q - 1;     while (1) {       rtree[id].Del(pos);       if (l == r) break;       int chld = id << 1, m = (l + r) >> 1;       if (idpos <= m)         r = m, id = chld;       else         l = m + 1, id = chld + 1;     }   }   int QueryRangeTree(int id, int l, int r, int x, int y, int ya, int yb) {     int res = 1000000000;     if (x <= l && r <= y)       res = rtree[id].Query(ya, yb);     else {       int chld = (id << 1), m = (l + r) >> 1;       res = 1000000000;       if (x <= m) res = min(res, QueryRangeTree(chld, l, m, x, y, ya, yb));       if (y > m) res = min(res, QueryRangeTree(chld + 1, m + 1, r, x, y, ya, yb));     }     return res;   }   struct Target {     int xa;     int ya;     int xb;     int yb;     int z;     int idx;     Target() {}     bool operator<(Target other) const {       if (z == other.z) return idx < other.idx;       return z < other.z;     }   };   Target arr2[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d %d %d , &arr2[i].xa, &arr2[i].xb, &arr2[i].ya, &arr2[i].yb,             &arr2[i].z);       arr2[i].idx = i;     }     sort(arr2, arr2 + n);     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d %d , &origin[i].x, &origin[i].y);       origin[i].idx = i;       X.push_back(origin[i].x);       arr[i] = origin[i];     }     sort(arr, arr + q);     sort(X.begin(), X.end());     BuildRangeTree(1, 0, q - 1);     memset(ans, -1, sizeof ans);     for (int i = 0; i < n; i++) {       int x1 = lower_bound(X.begin(), X.end(), arr2[i].xa) - X.begin();       int x2 = upper_bound(X.begin(), X.end(), arr2[i].xb) - X.begin();       x2--;       if (x1 <= x2) {         int res = QueryRangeTree(1, 0, q - 1, x1, x2, arr2[i].ya, arr2[i].yb);         if (res != 1000000000) {           ans[res] = arr2[i].idx;           UpdateRangeTree(res);         }       }     }     for (int i = 0; i < q; i++) printf( %d n , ans[i] + 1);     return 0;   }