#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
struct Plane {
  int x1, x2, y1, y2, z, id;
} p[MAXN];
struct Poi {
  int x, y, id;
} pi[MAXN];
int n, m, ans[MAXN], rev[MAXN * 2];
int mn[MAXN * 2][2], mx[MAXN * 2][2], mnp[MAXN * 2];
bool cmp(Plane a, Plane b) { return a.z < b.z; }
bool cmp0(Poi a, Poi b) { return a.x < b.x; }
bool cmp1(Poi a, Poi b) { return a.y < b.y; }
void upd(int p) {
  int a = mnp[p << 1], b = mnp[(p << 1) | 1];
  mnp[p] = min(a, b);
  return;
}
void buildt(int p, int l, int r, int d) {
  if (l == r) {
    rev[pi[l].id] = p, mnp[p] = pi[l].id;
    mn[p][0] = mx[p][0] = pi[l].x, mn[p][1] = mx[p][1] = pi[l].y;
    return;
  }
  int mid = (l + r) >> 1;
  nth_element(pi + l, pi + mid, pi + r + 1, d ? cmp0 : cmp1);
  buildt(p << 1, l, mid, d ^ 1);
  buildt((p << 1) | 1, mid + 1, r, d ^ 1);
  mn[p][0] = min(mn[p << 1][0], mn[(p << 1) | 1][0]);
  mn[p][1] = min(mn[p << 1][1], mn[(p << 1) | 1][1]);
  mx[p][0] = max(mx[p << 1][0], mx[(p << 1) | 1][0]);
  mx[p][1] = max(mx[p << 1][1], mx[(p << 1) | 1][1]);
  upd(p);
  return;
}
int query(int p, int l, int r, int xl, int xr, int yl, int yr) {
  if (xr < mn[p][0] || mx[p][0] < xl || yr < mn[p][1] || mx[p][1] < yl) {
    return 1e9;
  }
  if (xl <= mn[p][0] && mx[p][0] <= xr && yl <= mn[p][1] && mx[p][1] <= yr) {
    return mnp[p];
  }
  int mid = (l + r) >> 1;
  int a = query(p << 1, l, mid, xl, xr, yl, yr),
      b = query((p << 1) | 1, mid + 1, r, xl, xr, yl, yr);
  return min(a, b);
}
void modify(int p) {
  mnp[p] = 1e9;
  p /= 2;
  while (p) {
    upd(p);
    p /= 2;
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d%d", &p[i].x1, &p[i].x2, &p[i].y1, &p[i].y2, &p[i].z);
    p[i].id = i;
  }
  sort(p + 1, p + n + 1, cmp);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &pi[i].x, &pi[i].y);
    pi[i].id = i;
  }
  buildt(1, 1, m, 0);
  for (int i = 1; i <= n; i++) {
    int tmp = query(1, 1, m, p[i].x1, p[i].x2, p[i].y1, p[i].y2);
    if (tmp == 1e9) {
      continue;
    }
    ans[tmp] = p[i].id;
    modify(rev[tmp]);
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
