#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int ax[100000], bx[100000], x[100000], y[100000];
int ay[100000], by[100000], z[100000], o[100000], ans[100000];
map<int, deque<int>> at[200005];
template <class T>
T* node(T*& x) {
  if (x) return x;
  static deque<T> u;
  u.push_front(T());
  return x = &u.front();
}
class BoxTree {
 public:
  int now;
  BoxTree* u[4];
  BoxTree() : now(INF) { u[0] = u[1] = u[2] = u[3] = 0; }
  void modify(int x, int y, int ax, int ay, int bx, int by) {
    now = INF;
    if (ax + 1 >= bx && ay + 1 >= by) {
      if (!at[x][y].empty()) now = at[x][y].front();
      return;
    }
    int mx = (ax + bx) / 2, my = (ay + by) / 2;
    if (x < mx) {
      if (y < my)
        node(u[0])->modify(x, y, ax, ay, mx, my);
      else
        node(u[1])->modify(x, y, ax, my, mx, by);
    } else {
      if (y < my)
        node(u[2])->modify(x, y, mx, ay, bx, my);
      else
        node(u[3])->modify(x, y, mx, my, bx, by);
    }
    for (int i = 0; i < 4; i++)
      if (u[i]) now = min(now, u[i]->now);
  }
  int getmin(int px, int py, int qx, int qy, int ax, int ay, int bx, int by) {
    if (px <= ax && py <= ay && qx >= bx && qy >= by) return now;
    int mx = (ax + bx) / 2, my = (ay + by) / 2, ret = INF;
    if (px < mx && py < my && u[0])
      ret = min(ret, u[0]->getmin(px, py, qx, qy, ax, ay, mx, my));
    if (px < mx && qy > my && u[1])
      ret = min(ret, u[1]->getmin(px, py, qx, qy, ax, my, mx, by));
    if (qx > mx && py < my && u[2])
      ret = min(ret, u[2]->getmin(px, py, qx, qy, mx, ay, bx, my));
    if (qx > mx && qy > my && u[3])
      ret = min(ret, u[3]->getmin(px, py, qx, qy, mx, my, bx, by));
    return ret;
  }
};
int locate(int x, const vector<int>& u) {
  return upper_bound(u.begin(), u.end(), x) - u.begin() - 1;
}
int main() {
  BoxTree t;
  int n, m, W, H;
  scanf("%d", &n);
  vector<int> ux = {INF, -INF}, uy = ux;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d%d", ax + i, bx + i, ay + i, by + i, z + i);
    ux.push_back(ax[i]);
    ux.push_back(bx[i] += 1);
    uy.push_back(ay[i]);
    uy.push_back(by[i] += 1);
    o[i] = i;
  }
  sort(o, o + n, [](int l, int r) { return z[l] < z[r]; });
  sort(ux.begin(), ux.end());
  sort(uy.begin(), uy.end());
  ux.resize(W = unique(ux.begin(), ux.end()) - ux.begin());
  uy.resize(H = unique(uy.begin(), uy.end()) - uy.begin());
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", x + i, y + i);
    x[i] = locate(x[i], ux);
    y[i] = locate(y[i], uy);
    at[x[i]][y[i]].push_back(i);
    t.modify(x[i], y[i], 0, 0, W, H);
  }
  for (int w = 0; w < n; w++) {
    int i = o[w];
    ax[i] = locate(ax[i], ux);
    bx[i] = locate(bx[i], ux);
    ay[i] = locate(ay[i], uy);
    by[i] = locate(by[i], uy);
    int c = t.getmin(ax[i], ay[i], bx[i], by[i], 0, 0, W, H);
    if (c == INF) continue;
    at[x[c]][y[c]].pop_front();
    t.modify(x[c], y[c], 0, 0, W, H);
    ans[c] = i + 1;
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
}
