#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int cnt, curk;
int pos[N], fa[N];
struct Wall {
  int z, pos;
  int xmin, xmax, ymin, ymax;
  Wall() {}
  bool operator<(const Wall &x) const { return z < x.z; }
} w[N];
struct Queries {
  int x, y;
  int pos;
  Queries() {}
  bool operator<(const Queries &xx) const { return curk ? x < xx.x : y < xx.y; }
} ask[N];
struct K_Dimensional_Tree {
  struct KDT {
    int id, minval, x, y, xmin, xmax, ymin, ymax;
    int lson, rson;
    KDT() { minval = id = xmin = xmax = ymin = ymax = lson = rson = x = y = 0; }
  } t[N];
  void pushup(int u) {
    t[u].minval = t[u].id;
    if (t[u].lson) {
      t[u].minval = min(t[u].minval, t[t[u].lson].minval);
      t[u].xmin = min(t[u].xmin, t[t[u].lson].xmin);
      t[u].xmax = max(t[u].xmax, t[t[u].lson].xmax);
      t[u].ymin = min(t[u].ymin, t[t[u].lson].ymin);
      t[u].ymax = max(t[u].ymax, t[t[u].lson].ymax);
    }
    if (t[u].rson) {
      t[u].minval = min(t[u].minval, t[t[u].rson].minval);
      t[u].xmin = min(t[u].xmin, t[t[u].rson].xmin);
      t[u].xmax = max(t[u].xmax, t[t[u].rson].xmax);
      t[u].ymin = min(t[u].ymin, t[t[u].rson].ymin);
      t[u].ymax = max(t[u].ymax, t[t[u].rson].ymax);
    }
  }
  int BuildTree(int d, int l, int r) {
    int p = ++cnt, u = (l + r) / 2;
    curk = d;
    nth_element(ask + l, ask + u, ask + r + 1);
    t[p].minval = t[p].id = ask[u].pos;
    pos[ask[u].pos] = p;
    t[p].xmin = t[p].xmax = t[p].x = ask[u].x;
    t[p].ymin = t[p].ymax = t[p].y = ask[u].y;
    if (l < u) t[p].lson = BuildTree(d ^ 1, l, u - 1), fa[t[p].lson] = p;
    if (r > u) t[p].rson = BuildTree(d ^ 1, u + 1, r), fa[t[p].rson] = p;
    pushup(p);
    return p;
  }
  int Query(int p, int xl, int xr, int yl, int yr) {
    if (t[p].xmin > xr || t[p].xmax < xl || t[p].ymin > yr || t[p].ymax < yl)
      return 0x3f3f3f3f;
    if (xl <= t[p].xmin && t[p].xmax <= xr && yl <= t[p].ymin &&
        t[p].ymax <= yr)
      return t[p].minval;
    int ans = 0x3f3f3f3f;
    if (t[p].id != 0x3f3f3f3f && xl <= t[p].x && t[p].x <= xr && yl <= t[p].y &&
        t[p].y <= yr)
      ans = min(ans, t[p].id);
    if (t[p].lson) ans = min(ans, Query(t[p].lson, xl, xr, yl, yr));
    if (t[p].rson) ans = min(ans, Query(t[p].rson, xl, xr, yl, yr));
    return ans;
  }
  void Del(int p) {
    t[p].id = 0x3f3f3f3f;
    while (p) {
      pushup(p);
      p = fa[p];
    }
  }
} KD;
int n, ANS[N], q;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    w[i].xmin = read(), w[i].xmax = read(), w[i].ymin = read(),
    w[i].ymax = read(), w[i].z = read(), w[i].pos = i;
  sort(w + 1, w + n + 1);
  q = read();
  for (int i = 1; i <= q; i++)
    ask[i].x = read(), ask[i].y = read(), ask[i].pos = i;
  KD.BuildTree(0, 1, q);
  for (int i = 1; i <= n; i++) {
    int ans = KD.Query(1, w[i].xmin, w[i].xmax, w[i].ymin, w[i].ymax);
    if (ans == 0x3f3f3f3f) continue;
    ANS[ans] = w[i].pos;
    KD.Del(pos[ans]);
  }
  for (int i = 1; i <= q; i++) cout << ANS[i] << endl;
  return 0;
}
