#include <bits/stdc++.h>
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int mx = 1e5 + 5;
const int mod = 1e9 + 7;
const int x_move[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int y_move[] = {0, 0, 1, -1, 1, -1, 1, -1};
int n, m;
int rt;
const int de = 3;
int dep;
struct node {
  int pos[de];
  int l, r;
  bool exi;
  int sz;
  int fa;
  int mi[de], ma[de];
  bool operator<(const node &a) const { return pos[dep] < a.pos[dep]; }
  bool operator==(const node &a) const {
    for (int i = 0; i < de; i++)
      if (pos[i] != a.pos[i]) return false;
    return true;
  }
} a[mx];
int ans[mx];
int pos[mx];
struct kdtree {
  node kd[mx];
  int cnt;
  kdtree() {
    kd[0].exi = 0;
    kd[0].sz = 0;
    for (int i = 0; i < de; i++) kd[0].mi[i] = inf, kd[0].ma[i] = -inf;
  }
  void init(int n) {
    cnt = n;
    for (int i = 1; i <= n; i++)
      scanf("%d%d", &kd[i].pos[0], &kd[i].pos[1]), kd[i].pos[2] = i;
  }
  bool inr(node a, node b) {
    for (int i = 0; i < 2; i++)
      if (a.ma[i] > b.ma[i] || a.mi[i] < b.mi[i]) return false;
    return true;
  }
  bool in(node a, node b) {
    for (int i = 0; i < 2; i++)
      if (a.pos[i] > b.ma[i] || a.pos[i] < b.mi[i]) return false;
    return true;
  }
  bool sect(node a, node b) {
    for (int i = 0; i < 2; i++)
      if ((a.ma[i] < b.mi[i]) || (a.mi[i] > b.ma[i])) return false;
    return true;
  }
  void merge(node &a, node b, node c) {
    for (int i = 0; i < de; i++)
      if (a.exi)
        a.mi[i] = a.ma[i] = a.pos[i];
      else
        a.mi[i] = inf, a.ma[i] = -inf;
    a.sz = a.exi + b.sz + c.sz;
    for (int i = 0; i < de; i++) {
      a.mi[i] = min(a.mi[i], min(b.mi[i], c.mi[i]));
      a.ma[i] = max(a.ma[i], max(b.ma[i], c.ma[i]));
    }
  }
  int built(int l, int r, int k, int fa) {
    if (l > r) return 0;
    int mid = (l + r) / 2;
    dep = k % de;
    nth_element(kd + l, kd + mid, kd + r + 1);
    kd[mid].l = built(l, mid - 1, k + 1, mid);
    kd[mid].r = built(mid + 1, r, k + 1, mid);
    kd[mid].exi = 1;
    kd[mid].fa = fa;
    pos[kd[mid].pos[2]] = mid;
    merge(kd[mid], kd[kd[mid].l], kd[kd[mid].r]);
    rt = mid;
    return mid;
  }
  void query(int rt, node &b) {
    if (kd[rt].sz == 0) return;
    if (kd[rt].mi[2] > b.pos[2]) return;
    if (!sect(kd[rt], b)) return;
    if (inr(kd[rt], b)) {
      b.pos[2] = min(b.pos[2], kd[rt].mi[2]);
      return;
    }
    if (kd[rt].exi && in(kd[rt], b)) b.pos[2] = min(b.pos[2], kd[rt].pos[2]);
    query(kd[rt].l, b);
    query(kd[rt].r, b);
  }
  void del(int rt, node b, int k) {
    if (b == kd[rt]) {
      kd[rt].exi = 0;
      merge(kd[rt], kd[kd[rt].l], kd[kd[rt].r]);
      return;
    }
    dep = k % de;
    if (kd[rt] < b)
      del(kd[rt].r, b, k + 1);
    else
      del(kd[rt].l, b, k + 1);
    merge(kd[rt], kd[kd[rt].l], kd[kd[rt].r]);
  }
  void del(int rt) {
    kd[rt].exi = 0;
    while (rt) {
      merge(kd[rt], kd[kd[rt].l], kd[kd[rt].r]);
      rt = kd[rt].fa;
    }
  }
} kdtree;
int main() {
  int t, q, ca = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d%d%d%d", &a[i].mi[0], &a[i].ma[0], &a[i].mi[1], &a[i].ma[1],
          &a[i].pos[2]),
        a[i].mi[2] = i;
  dep = 2;
  sort(a + 1, a + n + 1);
  scanf("%d", &m);
  kdtree.init(m);
  kdtree.built(1, m, 1, 0);
  for (int i = 1; i <= n; i++) {
    a[i].pos[2] = inf;
    kdtree.query(rt, a[i]);
    if (a[i].pos[2] != inf) {
      ans[a[i].pos[2]] = a[i].mi[2];
      kdtree.del(pos[a[i].pos[2]]);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
