#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 p[de];
  int l, r;
  bool exi;
  int sz;
  int fa;
  int mi[de], ma[de];
  bool operator<(const node &a) const { return p[dep] < a.p[dep]; }
  bool operator==(const node &a) const {
    for (int i = 0; i < de; i++)
      if (p[i] != a.p[i]) return false;
    return true;
  }
} a[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].p[0], &kd[i].p[1]), kd[i].p[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.p[i] > b.ma[i] || a.p[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.p[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].p[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.p[2]) return;
    if (!sect(kd[rt], b)) return;
    if (inr(kd[rt], b)) {
      b.p[2] = min(b.p[2], kd[rt].mi[2]);
      return;
    }
    if (kd[rt].exi && in(kd[rt], b)) b.p[2] = min(b.p[2], kd[rt].p[2]);
    query(kd[rt].l, b);
    query(kd[rt].r, b);
  }
  int insert(int rt, int k, node b, int fa) {
    if (rt == 0) {
      cnt++;
      kd[cnt] = b;
      kd[cnt].exi = 1;
      kd[cnt].fa = fa;
      kd[cnt].l = 0;
      kd[cnt].r = 0;
      pos[b.p[2]] = cnt;
      merge(kd[cnt], kd[kd[cnt].l], kd[kd[cnt].r]);
      return cnt;
    }
    dep = k % de;
    if (kd[rt] < b)
      kd[rt].l = insert(kd[rt].l, k + 1, b, rt);
    else
      kd[rt].r = insert(kd[rt].r, k + 1, b, rt);
    merge(kd[rt], kd[kd[rt].l], kd[kd[rt].r]);
    return rt;
  }
  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 ans[mx];
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].p[2]),
        a[i].mi[2] = i;
  dep = 2;
  sort(a + 1, a + n + 1);
  scanf("%d", &m);
  kdtree.init(0);
  rt = 0;
  for (int i = 1; i <= m; i++) {
    node b;
    scanf("%d%d", &b.p[0], &b.p[1]);
    b.p[2] = i;
    rt = kdtree.insert(rt, 1, b, rt);
  }
  for (int i = 1; i <= n; i++) {
    a[i].p[2] = inf;
    kdtree.query(rt, a[i]);
    if (a[i].p[2] != inf) {
      ans[a[i].p[2]] = a[i].mi[2];
      kdtree.del(pos[a[i].p[2]]);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
