#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9;
struct node {
  int x, y, id;
} a[N];
struct plane {
  int x1, x2, y1, y2, z, t;
} q[N];
struct KDtree {
  int x1, x2, y1, y2, mi, po;
} t[N << 2];
int n, m, P, Q, ans[N];
bool cmp1(plane a, plane b) { return a.z < b.z; }
bool cmp2(node a, node b) { return a.x < b.x; }
bool cmp3(node a, node b) { return a.y < b.y; }
int check(KDtree a, plane b) {
  if (a.x1 >= b.x1 && a.x2 <= b.x2 && a.y1 >= b.y1 && a.y2 <= b.y2)
    return 2;
  else if (a.x1 > b.x2 || a.x2 < b.x1 || a.y1 > b.y2 || a.y2 < b.y1)
    return 0;
  else
    return 1;
}
void pushup(int p) {
  if (t[(p << 1)].mi < t[(p << 1 | 1)].mi)
    t[p].mi = t[(p << 1)].mi, t[p].po = t[(p << 1)].po;
  else
    t[p].mi = t[(p << 1 | 1)].mi, t[p].po = t[(p << 1 | 1)].po;
}
void build(int p, int l, int r, bool type) {
  if (l == r) {
    t[p] = (KDtree){a[l].x, a[l].x, a[l].y, a[l].y, a[l].id, l};
    return;
  }
  nth_element(a + l, a + ((l + r) >> 1), a + r + 1, type ? cmp3 : cmp2);
  build((p << 1), l, ((l + r) >> 1), !type),
      build((p << 1 | 1), ((l + r) >> 1) + 1, r, !type);
  pushup(p);
  t[p].x1 = min(t[(p << 1)].x1, t[(p << 1 | 1)].x1),
  t[p].x2 = max(t[(p << 1)].x2, t[(p << 1 | 1)].x2);
  t[p].y1 = min(t[(p << 1)].y1, t[(p << 1 | 1)].y1),
  t[p].y2 = max(t[(p << 1)].y2, t[(p << 1 | 1)].y2);
}
void query(int p, int l, int r, plane k) {
  if (!check(t[p], k) || t[p].mi > P) return;
  if (check(t[p], k) == 2) P = t[p].mi, Q = t[p].po;
  if (l == r) return;
  query((p << 1), l, ((l + r) >> 1), k),
      query((p << 1 | 1), ((l + r) >> 1) + 1, r, k);
}
void update(int p, int l, int r, int x, int y, int k) {
  if (l == r) {
    ans[t[p].mi] = k, t[p].mi = inf;
    return;
  }
  if (((l + r) >> 1) >= x)
    update((p << 1), l, ((l + r) >> 1), x, y, k);
  else
    update((p << 1 | 1), ((l + r) >> 1) + 1, r, x, y, k);
  pushup(p);
}
int main() {
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d%d%d", &q[i].x1, &q[i].x2, &q[i].y1, &q[i].y2, &q[i].z),
        q[i].t = i;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].x, &a[i].y), a[i].id = i;
  sort(q + 1, q + m + 1, cmp1);
  build(1, 1, n, 0);
  for (int i = 1; i <= m; ++i) {
    P = inf, Q = 0, query(1, 1, n, q[i]);
    if (P != inf) update(1, 1, n, Q, Q, q[i].t);
  }
  for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
  return 0;
}
