#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long read1() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 10;
struct P {
  int x, y;
} p[N];
struct Rec {
  int x1, y1, x2, y2, z;
  Rec() {}
  Rec(P q) : x1(q.x), y1(q.y), x2(q.x), y2(q.y) {}
  inline bool cover(const Rec &r) const {
    return x1 <= r.x1 && r.x2 <= x2 && y1 <= r.y1 && r.y2 <= y2;
  }
  inline bool jiao(const Rec &r) const {
    return !(x2 < r.x1 || x1 > r.x2) && !(y2 < r.y1 || y1 > r.y2);
  }
} R[N];
inline bool cpx(int a, int b) {
  return p[a].x != p[b].x ? p[a].x < p[b].x : p[a].y < p[b].y;
}
inline bool cpy(int a, int b) {
  return p[a].y != p[b].y ? p[a].y < p[b].y : p[a].x < p[b].x;
}
inline bool cpz(int a, int b) { return R[a].z < R[b].z; }
struct KD_T {
  Rec val[8 * N];
  bool flag[8 * N];
  void pull(int rt) {
    val[rt].x1 = min(val[rt << 1].x1, val[rt << 1 | 1].x1);
    val[rt].y1 = min(val[rt << 1].y1, val[rt << 1 | 1].y1);
    val[rt].x2 = max(val[rt << 1].x2, val[rt << 1 | 1].x2);
    val[rt].y2 = max(val[rt << 1].y2, val[rt << 1 | 1].y2);
    val[rt].z = min(val[rt << 1].z, val[rt << 1 | 1].z);
  }
  void init(int rt, int n, int *lst, int lv) {
    if (n == 1) {
      val[rt] = p[lst[0]];
      val[rt].z = lst[0];
      flag[rt] = 1;
      return;
    }
    sort(lst, lst + n, lv % 2 == 0 ? cpx : cpy);
    init(rt << 1, n / 2, lst, lv + 1);
    init(rt << 1 | 1, n - n / 2, lst + n / 2, lv + 1);
    pull(rt);
  }
  void del_min(int rt) {
    if (flag[rt]) {
      val[rt].z = 0x3f3f3f3f;
      return;
    }
    if (val[rt << 1].z == val[rt].z)
      del_min(rt * 2);
    else
      del_min(rt * 2 + 1);
    pull(rt);
  }
  void up(int rt) {
    do pull(rt);
    while (rt /= 2);
  }
  pair<int, int> Q(int rt, const Rec &r) {
    if (!r.jiao(val[rt])) return make_pair(0x3f3f3f3f, -1);
    if (r.cover(val[rt])) return make_pair(val[rt].z, rt);
    return min(Q(rt * 2, r), Q(rt * 2 + 1, r));
  }
} kdt;
int n, m;
int ans[N], lst[N], srt[N];
int main() {
  n = read();
  for (int i = 0; i <= n - 1; i++) {
    R[i].x1 = read();
    R[i].x2 = read();
    R[i].y1 = read();
    R[i].y2 = read();
    R[i].z = read();
  }
  m = read();
  for (int i = 0; i <= m - 1; i++) p[i].x = read(), p[i].y = read();
  for (int i = 0; i <= m - 1; i++) lst[i] = i;
  kdt.init(1, m, lst, 0);
  for (int i = 0; i <= n - 1; i++) srt[i] = i;
  sort(srt, srt + n, cpz);
  for (int i = 0; i <= n - 1; i++) {
    pair<int, int> ret = kdt.Q(1, R[srt[i]]);
    if (ret.first == 0x3f3f3f3f) continue;
    kdt.del_min(ret.second);
    kdt.up(ret.second / 2);
    ans[ret.first] = srt[i] + 1;
  }
  for (int i = 0; i <= m - 1; i++) printf("%d\n", ans[i]);
}
