#include <bits/stdc++.h>
using namespace std;
int rd() { return RAND_MAX == 32767 ? ((rand() << 15) ^ rand()) : rand(); }
const int maxn = 100010;
const int maxt = 3000000;
const int inf = 1000000000;
int tt;
int res[maxn];
int p[maxt], key[maxt], opt[maxt], val[maxt], ch[maxt][2];
vector<int> ID[maxn];
struct Point {
  int x, y, id;
  bool operator<(const Point &o) const { return x < o.x; }
};
Point a[maxn];
void Rotate(int t, int x) {
  int k = ch[t][x];
  ch[t][x] = ch[k][1 - x];
  ch[k][1 - x] = t;
  if (p[t]) ch[p[t]][t == ch[p[t]][1]] = k;
  p[k] = p[t];
  p[t] = k;
  p[ch[t][x]] = t;
  opt[k] = opt[t];
  opt[t] = min(min(opt[ch[t][0]], opt[ch[t][1]]), val[t]);
}
void Splay(int t, int gnd) {
  if (t == gnd) return;
  for (;;) {
    if (p[t] == gnd) {
      Rotate(p[t], t == ch[p[t]][1]);
      return;
    }
    int flag = p[p[t]] == gnd, k = p[t];
    if ((t == ch[p[t]][1]) ^ (k == ch[p[k]][1])) {
      Rotate(p[t], t == ch[p[t]][1]);
      Rotate(p[t], t == ch[p[t]][1]);
    } else {
      Rotate(p[k], k == ch[p[k]][1]);
      Rotate(p[t], t == ch[p[t]][1]);
    }
    if (flag) return;
  }
}
struct Tree {
  int l, r, t;
  Tree *lc, *rc;
  void Insert(int x, int y) {
    int k;
    for (k = t; ch[k][x > key[k]]; k = ch[k][x > key[k]])
      opt[k] = min(opt[k], y);
    ch[k][x > key[k]] = ++tt;
    p[tt] = k;
    ch[tt][0] = ch[tt][1] = 0;
    key[tt] = x;
    val[tt] = opt[tt] = y;
    if (y != inf) ID[y].push_back(tt);
    Splay(tt, ch[t][0]);
  }
  int Lower(int x) {
    int k;
    for (k = t;;)
      if (key[k] >= x)
        k = ch[k][0];
      else {
        int kk;
        for (kk = ch[k][1]; ch[kk][0]; kk = ch[kk][0])
          ;
        if (kk == 0 || key[kk] >= x) break;
        k = ch[k][1];
      }
    return k;
  }
  int Upper(int x) {
    int k;
    for (k = t;;)
      if (key[k] <= x)
        k = ch[k][1];
      else {
        int kk;
        for (kk = ch[k][0]; ch[kk][1]; kk = ch[kk][1])
          ;
        if (kk == 0 || key[kk] <= x) break;
        k = ch[k][0];
      }
    return k;
  }
  int Search(int yl, int yr) {
    int lt = Lower(yl), rt = Upper(yr);
    Splay(lt, ch[t][0]);
    Splay(rt, ch[ch[t][0]][1]);
    return opt[ch[ch[ch[t][0]][1]][0]];
  }
  void Init() {
    t = ++tt;
    opt[0] = inf;
    p[0] = ch[0][0] = ch[0][1] = 0;
    p[t] = 0;
    ch[t][0] = 0;
    ch[t][1] = 0;
    key[t] = inf * 2;
    val[t] = opt[t] = inf;
    Insert(-inf, inf);
    Insert(inf, inf);
    for (int i = l; i < r; i++) Insert(a[i].y, a[i].id);
  }
  Tree(int l_, int r_) : l(l_), r(r_) {
    Init();
    lc = l + 1 < r ? new Tree(l, (l + r) >> 1) : NULL;
    rc = l + 1 < r ? new Tree((l + r) >> 1, r) : NULL;
  }
  int Query(int xl, int xr, int yl, int yr) {
    if (xr < a[l].x || xl > a[r - 1].x) return inf;
    if (xl <= a[l].x && xr >= a[r - 1].x) return Search(yl, yr);
    int res = inf, m = (l + r) >> 1;
    if (xl <= a[m - 1].x) res = min(res, lc->Query(xl, xr, yl, yr));
    if (xr >= a[m].x) res = min(res, rc->Query(xl, xr, yl, yr));
    return res;
  }
};
int Prev(int x) {
  int k;
  if (ch[x][0]) {
    for (k = ch[x][0]; ch[k][1]; k = ch[k][1])
      ;
  } else {
    for (k = x; k == ch[p[k]][0]; k = p[k])
      ;
    k = p[k];
  }
  return k;
}
int Succ(int x) {
  int k;
  if (ch[x][1]) {
    for (k = ch[x][1]; ch[k][0]; k = ch[k][0])
      ;
  } else {
    for (k = x; k == ch[p[k]][1]; k = p[k])
      ;
    k = p[k];
  }
  return k;
}
void Fresh(int t) { opt[t] = min(min(opt[ch[t][0]], opt[ch[t][1]]), val[t]); }
void Delete(int k) {
  int t, pre = Prev(k), suc = Succ(k);
  for (t = k; p[t]; t = p[t])
    ;
  Splay(pre, ch[t][0]);
  Splay(suc, ch[ch[t][0]][1]);
  ch[ch[ch[t][0]][1]][0] = 0;
  Fresh(ch[ch[t][0]][1]);
  Fresh(ch[t][0]);
  Fresh(t);
  assert(ch[k][0] + ch[k][1] == 0);
}
Tree *root;
struct Quest {
  int id, xl, xr, yl, yr, z;
  bool operator<(const Quest &o) const { return z < o.z; }
};
Quest q[maxn];
int main() {
  int n, m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d%d", &q[i].xl, &q[i].xr, &q[i].yl, &q[i].yr, &q[i].z);
    q[i].id = i;
  }
  sort(q, q + m);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    a[i].id = i;
  }
  sort(a, a + n);
  tt = 0;
  root = new Tree(0, n);
  memset(res, 0, sizeof(res));
  for (int i = 0; i < m; i++) {
    int cnt = root->Query(q[i].xl, q[i].xr, q[i].yl, q[i].yr);
    if (cnt != inf) {
      res[cnt] = q[i].id + 1;
      for (__typeof(ID[cnt].begin()) e = ID[cnt].begin(); e != ID[cnt].end();
           e++)
        Delete(*e);
    }
  }
  for (int i = 0; i < n; i++) cout << res[i] << endl;
  return 0;
}
