#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
struct P {
  int x1, y1, x2, y2, z, id;
  void in() { scanf("%d%d%d%d%d", &x1, &x2, &y1, &y2, &z); }
} dt[N];
struct kd {
  int l, r, x1, x2, y1, y2, key, fa;
} tree[N];
bool cmp(P x, P y) { return x.z < y.z; }
int x[N], y[N], b[N];
bool us[N];
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
bool cmpx(int a, int b) { return x[a] < x[b]; }
bool cmpy(int a, int b) { return y[a] < y[b]; }
void up(int t) {
  tree[t].x1 = tree[t].x2 = x[t];
  tree[t].y1 = tree[t].y2 = y[t];
  if (!us[t])
    tree[t].key = t;
  else
    tree[t].key = N;
  if (tree[t].l) {
    tree[t].key = min(tree[t].key, tree[tree[t].l].key);
    tree[t].x1 = min(tree[t].x1, tree[tree[t].l].x1);
    tree[t].x2 = max(tree[t].x2, tree[tree[t].l].x2);
    tree[t].y1 = min(tree[t].y1, tree[tree[t].l].y1);
    tree[t].y2 = max(tree[t].y2, tree[tree[t].l].y2);
  }
  if (tree[t].r) {
    tree[t].key = min(tree[t].key, tree[tree[t].r].key);
    tree[t].x1 = min(tree[t].x1, tree[tree[t].r].x1);
    tree[t].x2 = max(tree[t].x2, tree[tree[t].r].x2);
    tree[t].y1 = min(tree[t].y1, tree[tree[t].r].y1);
    tree[t].y2 = max(tree[t].y2, tree[tree[t].r].y2);
  }
}
int build(int L, int R, int f, int c) {
  if (L > R) return 0;
  int m = (L + R) / 2;
  nth_element(b + L, b + m, b + R + 1, c ? cmpx : cmpy);
  int nd = b[m];
  tree[nd].fa = f;
  tree[nd].l = build(L, m - 1, nd, 1 - c);
  tree[nd].r = build(m + 1, R, nd, 1 - c);
  tree[nd].key = nd;
  up(nd);
  return nd;
}
int ret, rt[N];
void work(int x1, int x2, int y1, int y2, int t) {
  if (!t || x1 > tree[t].x2 || x2 < tree[t].x1 || y1 > tree[t].y2 ||
      y2 < tree[t].y1 || ret <= tree[t].key)
    return;
  if (x1 <= tree[t].x1 && x2 >= tree[t].x2 && y1 <= tree[t].y1 &&
      y2 >= tree[t].y2) {
    ret = tree[t].key;
    return;
  }
  if (!us[t] && x1 <= x[t] && x2 >= x[t] && y1 <= y[t] && y2 >= y[t]) {
    ret = min(ret, t);
  }
  work(x1, x2, y1, y2, tree[t].l);
  work(x1, x2, y1, y2, tree[t].r);
}
int main() {
  int n, m, i;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    dt[i].in();
    dt[i].id = i;
  }
  sort(dt, dt + m, cmp);
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    b[i] = i;
  }
  int root = build(1, n, 0, 0);
  for (i = 0; i < m; i++) {
    ret = N;
    work(dt[i].x1, dt[i].x2, dt[i].y1, dt[i].y2, root);
    if (ret != N) {
      rt[ret] = dt[i].id + 1;
      int u = ret;
      tree[u].key = N;
      us[u] = true;
      while (u) {
        up(u);
        u = tree[u].fa;
      }
    }
  }
  for (i = 1; i <= n; i++) printf("%d\n", rt[i]);
  return 0;
}
