#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9;
int read() {
  int x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (f = -f);
  for (x = ch ^ 48; isdigit(ch = getchar());
       x = (x << 3) + (x << 1) + (ch ^ 48))
    ;
  return x * f;
}
template <class T>
T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
T Min(T a, T b) {
  return a < b ? a : b;
}
int n, m, res, cnt, nowk, root, fa[N], pos[N], ans[N];
struct tim {
  int xl, xr, yl, yr, z, id;
  friend bool operator<(tim a, tim b) { return a.z < b.z; }
} b[N];
struct point {
  int x, y, id;
  friend bool operator<(point a, point b) {
    return nowk ? a.x < b.x : a.y < b.y;
  }
} s[N];
struct node {
  int x, y, id, ls, rs, mn, mnx, mny, mxx, mxy;
} tr[N];
void pushup(int o) {
  tr[o].mn = tr[o].id;
  if (tr[o].ls) {
    tr[o].mn = min(tr[o].mn, tr[tr[o].ls].mn);
    tr[o].mnx = min(tr[o].mnx, tr[tr[o].ls].mnx);
    tr[o].mny = min(tr[o].mny, tr[tr[o].ls].mny);
    tr[o].mxx = max(tr[o].mxx, tr[tr[o].ls].mxx);
    tr[o].mxy = max(tr[o].mxy, tr[tr[o].ls].mxy);
  }
  if (tr[o].rs) {
    tr[o].mn = min(tr[o].mn, tr[tr[o].rs].mn);
    tr[o].mnx = min(tr[o].mnx, tr[tr[o].rs].mnx);
    tr[o].mny = min(tr[o].mny, tr[tr[o].rs].mny);
    tr[o].mxx = max(tr[o].mxx, tr[tr[o].rs].mxx);
    tr[o].mxy = max(tr[o].mxy, tr[tr[o].rs].mxy);
  }
}
void build(int Fa, int &o, int l, int r, int K) {
  int mid = (l + r) >> 1;
  o = ++cnt;
  nowk = K;
  nth_element(s + l, s + mid, s + r + 1);
  pos[s[mid].id] = o;
  fa[o] = Fa;
  tr[o].id = tr[o].mn = s[mid].id;
  tr[o].x = tr[o].mnx = tr[o].mxx = s[mid].x;
  tr[o].y = tr[o].mny = tr[o].mxy = s[mid].y;
  if (l <= mid - 1) build(o, tr[o].ls, l, mid - 1, K ^ 1);
  if (mid + 1 <= r) build(o, tr[o].rs, mid + 1, r, K ^ 1);
  pushup(o);
}
void query(int o, int xl, int yl, int xr, int yr) {
  if (tr[o].mxx < xl || tr[o].mnx > xr || tr[o].mxy < yl || tr[o].mny > yr)
    return;
  if (xl <= tr[o].mnx && tr[o].mxx <= xr && yl <= tr[o].mny && tr[o].mxy <= yr)
    return res = min(res, tr[o].mn), void();
  if (tr[o].id != inf && xl <= tr[o].x && tr[o].x <= xr && yl <= tr[o].y &&
      tr[o].y <= yr)
    res = min(res, tr[o].id);
  if (tr[o].ls) query(tr[o].ls, xl, yl, xr, yr);
  if (tr[o].rs) query(tr[o].rs, xl, yl, xr, yr);
}
void remove(int x) {
  tr[x].id = inf;
  while (x) pushup(x), x = fa[x];
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    b[i].xl = read();
    b[i].xr = read();
    b[i].id = i;
    b[i].yl = read();
    b[i].yr = read();
    b[i].z = read();
  }
  m = read();
  for (int i = 1; i <= m; ++i) s[i].x = read(), s[i].y = read(), s[i].id = i;
  build(0, root, 1, m, 0);
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    res = inf;
    query(root, b[i].xl, b[i].yl, b[i].xr, b[i].yr);
    if (res != inf) ans[res] = b[i].id, remove(pos[res]);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
