#include <bits/stdc++.h>
using namespace std;
struct box {
  int xa, ya, xb, yb, z, id;
};
struct gun {
  int x, y, id;
  bool operator<(const gun &t) const {
    if (y != t.y) return y < t.y;
    return id < t.id;
  }
};
struct rangeNode {
  vector<int> stri;
  vector<gun> tik;
  void buildSegTree() {
    if (tik.size() == 0) return;
    int p = 1;
    while (p < tik.size()) p *= 2;
    stri.resize(2 * p, 0);
    build(0, 0, tik.size() - 1);
  }
  void build(int nod, int ki, int ka) {
    if (ki == ka) {
      stri[nod] = tik[ki].id;
    } else if (ki < ka) {
      int tgh = (ki + ka) >> 1;
      build(2 * nod + 1, ki, tgh);
      build(2 * nod + 2, tgh + 1, ka);
      stri[nod] = min(stri[2 * nod + 1], stri[2 * nod + 2]);
    }
  }
  int getMin(int ya, int yb) {
    int a, b;
    gun ga = (gun){ya, ya, 0};
    gun gb = (gun){yb, yb + 1, 0};
    a = lower_bound(tik.begin(), tik.end(), ga) - tik.begin();
    b = lower_bound(tik.begin(), tik.end(), gb) - tik.begin();
    if (a >= b) return 2123123123;
    return getMinRec(a, b - 1, 0, 0, tik.size() - 1);
  }
  int getMinRec(int a, int b, int nod, int ki, int ka) {
    if ((a <= ki) && (ka <= b)) {
      return stri[nod];
    } else {
      int tgh = (ki + ka) >> 1;
      int ret = 2123123123;
      if (a <= tgh) ret = min(ret, getMinRec(a, b, 2 * nod + 1, ki, tgh));
      if (b > tgh) ret = min(ret, getMinRec(a, b, 2 * nod + 2, tgh + 1, ka));
      return ret;
    }
  }
  void removeId(gun tgt) {
    int ki = 0;
    int ka = tik.size() - 1;
    int tgh;
    while (ki <= ka) {
      tgh = (ki + ka) >> 1;
      if (tgt < tik[tgh]) {
        ka = tgh - 1;
      } else if (tik[tgh] < tgt) {
        ki = tgh + 1;
      } else {
        break;
      }
    }
    removeRec(tgh, 0, 0, tik.size() - 1);
  }
  void removeRec(int id, int nod, int ki, int ka) {
    if (ki == ka) {
      stri[nod] = 2123123123;
    } else {
      int tgh = (ki + ka) >> 1;
      if (id <= tgh) removeRec(id, 2 * nod + 1, ki, tgh);
      if (id > tgh) removeRec(id, 2 * nod + 2, tgh + 1, ka);
      stri[nod] = min(stri[2 * nod + 1], stri[2 * nod + 2]);
    }
  }
};
int n, m;
int ans[100002];
box ab[100002];
gun shot[100002];
rangeNode rtree[4 * 131072];
vector<int> compx;
bool komz(const box &a, const box &b) { return a.z < b.z; }
void add(gun g, int nod, int ki, int ka) {
  rtree[nod].tik.push_back(g);
  if (ki < ka) {
    int tgh = (ki + ka) >> 1;
    if (g.x <= compx[tgh]) add(g, 2 * nod + 1, ki, tgh);
    if (g.x > compx[tgh]) add(g, 2 * nod + 2, tgh + 1, ka);
  }
}
void makeRangeTree(int sz) {
  int p = 1;
  while (p < sz) p *= 2;
  for (int i = 0; i < 2 * p; i++) {
    sort(rtree[i].tik.begin(), rtree[i].tik.end());
    rtree[i].buildSegTree();
  }
}
int queryMinIndex(int xa, int ya, int xb, int yb, int nod, int ki, int ka) {
  if ((xb < compx[ki]) || (compx[ka] < xa)) {
    return 2123123123;
  } else if ((xa <= compx[ki]) && (compx[ka] <= xb)) {
    return rtree[nod].getMin(ya, yb);
  } else {
    int tgh = (ki + ka) >> 1;
    int ret = 2123123123;
    if (xa <= compx[tgh])
      ret = min(ret, queryMinIndex(xa, ya, xb, yb, 2 * nod + 1, ki, tgh));
    if (xb > compx[tgh])
      ret = min(ret, queryMinIndex(xa, ya, xb, yb, 2 * nod + 2, tgh + 1, ka));
    return ret;
  }
}
void removeGun(int id, int nod, int ki, int ka) {
  rtree[nod].removeId(shot[id]);
  if (ki < ka) {
    int tgh = (ki + ka) >> 1;
    if (shot[id].x <= compx[tgh]) removeGun(id, 2 * nod + 1, ki, tgh);
    if (shot[id].x > compx[tgh]) removeGun(id, 2 * nod + 2, tgh + 1, ka);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d%d", &ab[i].xa, &ab[i].xb, &ab[i].ya, &ab[i].yb, &ab[i].z);
    ab[i].id = i;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &shot[i].x, &shot[i].y);
    shot[i].id = i;
    compx.push_back(shot[i].x);
  }
  sort(compx.begin(), compx.end());
  compx.resize(unique(compx.begin(), compx.end()) - compx.begin());
  for (int i = 0; i < m; i++) {
    add(shot[i], 0, 0, compx.size() - 1);
  }
  makeRangeTree(compx.size());
  sort(ab, ab + n, komz);
  for (int i = 0; i < n; i++) {
    int mid = queryMinIndex(ab[i].xa, ab[i].ya, ab[i].xb, ab[i].yb, 0, 0,
                            compx.size() - 1);
    if (mid != 2123123123) {
      ans[mid] = ab[i].id + 1;
      removeGun(mid, 0, 0, compx.size() - 1);
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
