#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
const double al = 0.7;
const int inf = 1e9;
int read() {
  int x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
int n, m, k, opt, rt, cnt, ans[M], pos[M], fa[M];
int mi[M][2], mx[M][2], Min[M], ls[M], rs[M];
struct node {
  int x[2], val;
} a[M], v[M];
struct data {
  int x1, y1, x2, y2, v, id;
  bool operator<(const data &b) const { return v < b.v; }
} b[M];
void up(int x) {
  for (int i = 0; i < 2; i++) mi[x][i] = mx[x][i] = v[x].x[i];
  if (ls[x])
    for (int i = 0; i < 2; i++) {
      mx[x][i] = max(mx[x][i], mx[ls[x]][i]);
      mi[x][i] = min(mi[x][i], mi[ls[x]][i]);
    }
  if (rs[x])
    for (int i = 0; i < 2; i++) {
      mx[x][i] = max(mx[x][i], mx[rs[x]][i]);
      mi[x][i] = min(mi[x][i], mi[rs[x]][i]);
    }
  Min[x] = v[x].val;
  if (ls[x]) Min[x] = min(Min[x], Min[ls[x]]);
  if (rs[x]) Min[x] = min(Min[x], Min[rs[x]]);
}
int cmp(node a, node b) { return a.x[opt] < b.x[opt]; }
void build(int &x, int l, int r, int wd) {
  if (l > r) return;
  x = ++cnt;
  int mid = (l + r) >> 1;
  opt = wd;
  nth_element(a + l, a + mid, a + r + 1, cmp);
  v[x] = a[mid];
  pos[v[x].val] = x;
  build(ls[x], l, mid - 1, wd ^ 1);
  build(rs[x], mid + 1, r, wd ^ 1);
  fa[ls[x]] = fa[rs[x]] = x;
  up(x);
}
int in(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  return x1 <= x3 && x4 <= x2 && y1 <= y3 && y4 <= y2;
}
int out(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  return x1 > x4 || x2 < x3 || y1 > y4 || y2 < y3;
}
int ask(int x, int x1, int y1, int x2, int y2) {
  if (!x) return inf;
  if (in(x1, y1, x2, y2, mi[x][0], mi[x][1], mx[x][0], mx[x][1])) return Min[x];
  if (out(x1, y1, x2, y2, mi[x][0], mi[x][1], mx[x][0], mx[x][1])) return inf;
  int r = inf;
  if (in(x1, y1, x2, y2, v[x].x[0], v[x].x[1], v[x].x[0], v[x].x[1]))
    r = v[x].val;
  r = min(r, ask(ls[x], x1, y1, x2, y2));
  r = min(r, ask(rs[x], x1, y1, x2, y2));
  return r;
}
void del(int x) {
  v[x].val = inf;
  while (x) {
    up(x);
    x = fa[x];
  }
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read(), c = read(), d = read(), z = read();
    b[i] = data{x, c, y, d, z, i};
  }
  sort(b + 1, b + 1 + n);
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    a[i] = node{x, y, i};
  }
  build(rt, 1, m, 0);
  for (int i = 1; i <= n; i++) {
    int t = ask(rt, b[i].x1, b[i].y1, b[i].x2, b[i].y2);
    if (t == inf) continue;
    int x = pos[t];
    ans[t] = b[i].id;
    del(x);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
