#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int w = 0, x = 0;
  char c = getchar();
  while (!isdigit(c)) w |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  return w ? -x : x;
}
namespace star {
const int maxn = 1e5 + 10, INF = 0x3f3f3f3f;
int n, m, ans[maxn], q[maxn];
int o;
struct node {
  int x[2];
  node() {}
  bool operator<(const node &b) const { return x[o] < b.x[o]; }
} a[maxn];
struct mat {
  int x[2][2];
  mat() {
    for (int t = 0; t < 2; t++) x[t][0] = INF, x[t][1] = -INF;
  }
  mat(node a) { x[0][0] = x[0][1] = a.x[0], x[1][0] = x[1][1] = a.x[1]; }
  mat(mat a, mat b) {
    for (int t = 0; t < 2; t++)
      x[t][0] = min(a.x[t][0], b.x[t][0]), x[t][1] = max(a.x[t][1], b.x[t][1]);
  }
  friend bool cross(const mat &a, const mat &b) {
    bool ok = true;
    for (int t = 0; t < 2; t++)
      if (a.x[t][1] < b.x[t][0] or a.x[t][0] > b.x[t][1]) ok = false;
    return ok;
  }
  bool in(const mat &b) const {
    bool ok = true;
    for (int t = 0; t < 2; t++)
      if (b.x[t][0] < x[t][0] or b.x[t][1] > x[t][1]) ok = false;
    return ok;
  }
  bool in(const node &b) const { return in(mat(b)); }
  bool operator<(const mat &b) const { return x[0][0] < b.x[0][0]; }
} e[maxn];
pair<pair<int, int>, mat> b[maxn];
int rt, ls[maxn], rs[maxn], mn[maxn], fa[maxn];
bool del[maxn];
inline void pushup(int ro) {
  e[ro] = mat(mat(a[q[ro]]), mat(e[ls[ro]], e[rs[ro]])),
  mn[ro] = min({del[ro] ? m + 1 : ro, mn[ls[ro]], mn[rs[ro]]},
               [](int a, int b) { return q[a] < q[b]; });
}
int build(int l = 1, int r = m) {
  if (l > r) return 0;
  if (l == r) return e[l] = mat(a[q[l]]), mn[l] = l;
  o ^= 1;
  int ro = (l + r) >> 1;
  nth_element(q + l, q + ro, q + r + 1,
              [](int x, int y) { return a[x] < a[y]; });
  fa[ls[ro] = build(l, ro - 1)] = ro, fa[rs[ro] = build(ro + 1, r)] = ro;
  pushup(ro);
  o ^= 1;
  return ro;
}
inline void erase(int x) {
  if (del[x] or x > m) return;
  del[x] = true;
  for (; x; x = fa[x]) pushup(x);
}
int query(mat x, int ro = rt) {
  if (!cross(x, e[ro])) return m + 1;
  if (x.in(e[ro])) return mn[ro];
  return min({!del[ro] and x.in(a[q[ro]]) ? ro : m + 1, query(x, ls[ro]),
              query(x, rs[ro])},
             [](int a, int b) { return q[a] < q[b]; });
}
inline void work() {
  n = read();
  for (int i = 1; i <= n; i++)
    b[i].second.x[0][0] = read(), b[i].second.x[0][1] = read(),
    b[i].second.x[1][0] = read(), b[i].second.x[1][1] = read(),
    b[i].first.first = read(), b[i].first.second = i;
  sort(b + 1, b + 1 + n);
  m = read(), mn[0] = m + 1, q[m + 1] = m + 1;
  for (int i = 1; i <= m; i++) a[i].x[0] = read(), a[i].x[1] = read(), q[i] = i;
  rt = build();
  for (int i = 1; i <= n; i++) {
    int x = query(b[i].second);
    erase(x);
    ans[q[x]] = b[i].first.second;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
}  // namespace star
signed main() {
  star::work();
  return 0;
}
