#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int MaxN = 100000 + 5;
const int MaxM = 100000 + 5;
const int LOG = 22;
const int MaxNode = MaxM * LOG + MaxN * 4 * 2;
struct Node {
  int key, id, minID, size;
  Node *fa, *c[2];
  Node() {
    c[0] = c[1] = this;
    size = 0;
    minID = oo;
  }
  Node(int _key, int _id, Node* _fa, Node* _c0, Node* _c1) {
    key = _key;
    id = _id;
    fa = _fa;
    c[0] = _c0;
    c[1] = _c1;
  }
  void update() {
    size = c[0]->size + 1 + c[1]->size;
    c[0]->fa = c[1]->fa = this;
    minID = min(id, min(c[0]->minID, c[1]->minID));
  }
  void zig(bool d) {
    Node *x = fa, *y = x->fa;
    x->c[d] = c[!d];
    x->update();
    c[!d] = x;
    x->fa = this;
    if (y->c[0] == x) {
      y->c[0] = this;
    }
    if (y->c[1] == x) {
      y->c[1] = this;
    }
    fa = y;
  }
} Tnull, *null = &Tnull, *cbuf, buf[MaxNode];
struct Splay {
  Node* root;
  void init() {
    root = new (cbuf++) Node(oo, 0, null, null, null);
    root->update();
    root = new (cbuf++) Node(-oo, 0, null, null, root);
    root->update();
  }
  void splay(Node* now, Node* des) {
    bool flag = des == root;
    Node* ancestor = des->fa;
    while (now->fa != ancestor) {
      bool d = now->fa->c[1] == now;
      if (now->fa->fa == ancestor) {
        now->zig(d);
        break;
      }
      bool dd = now->fa->fa->c[1] == now->fa;
      if (d != dd) {
        now->zig(d);
        now->zig(dd);
      } else {
        now->fa->zig(dd);
        now->zig(d);
      }
    }
    now->update();
    if (flag) {
      root = now;
    }
    while (now != root) {
      now = now->fa;
      now->update();
    }
  }
  void select(int k, Node* des) {
    Node* now = des;
    while (now->c[0]->size != k) {
      if (now->c[0]->size > k) {
        now = now->c[0];
      } else {
        k -= now->c[0]->size + 1;
        now = now->c[1];
      }
    }
    splay(now, des);
  }
  void lower_bound(int x, int id, Node* des, int d) {
    Node* now = des;
    int tmp = 0;
    while (now != null) {
      if (x < now->key || (x == now->key && id <= now->id)) {
        now = now->c[0];
      } else {
        tmp += now->c[0]->size + 1;
        now = now->c[1];
      }
    }
    select(tmp + d, des);
  }
  void ins(int x, int id) {
    root = new (cbuf++) Node(x, id, null, root->c[0], root);
    root->c[1]->c[0] = null;
    root->c[1]->update();
    root->update();
  }
  void del() {
    Node* oldroot = root;
    root = root->c[1];
    select(0, root);
    root->c[0] = oldroot->c[0];
    root->update();
  }
};
struct Rectangle {
  int x1, x2, y1, y2, z, lab;
  void load(int _lab) {
    lab = _lab;
    scanf("%d%d%d%d%d", &x1, &x2, &y1, &y2, &z);
  }
  bool operator<(const Rectangle& t) const { return z < t.z; }
} rec[MaxN];
int N, M;
int x[MaxM], y[MaxM], ans[MaxM];
int coY[MaxM], top;
Splay sp[MaxM * 4];
void modify(int now, int l, int r, int x, int y, int id, int d) {
  sp[now].lower_bound(x, id, sp[now].root, 0);
  if (d == 1) {
    sp[now].ins(x, id);
  } else {
    sp[now].del();
  }
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  if (y <= coY[mid]) {
    modify(now * 2, l, mid, x, y, id, d);
  } else {
    modify(now * 2 + 1, mid + 1, r, x, y, id, d);
  }
}
int query(int now, int l, int r, int lab) {
  int res = oo;
  if (rec[lab].y1 <= coY[l] && rec[lab].y2 >= coY[r]) {
    sp[now].lower_bound(rec[lab].x1, -1, sp[now].root, -1);
    sp[now].lower_bound(rec[lab].x2 + 1, -1, sp[now].root->c[1], 0);
    return min(res, sp[now].root->c[1]->c[0]->minID);
  }
  int mid = (l + r) / 2;
  if (rec[lab].y1 <= coY[mid]) {
    res = min(res, query(now * 2, l, mid, lab));
  }
  if (rec[lab].y2 >= coY[mid + 1]) {
    res = min(res, query(now * 2 + 1, mid + 1, r, lab));
  }
  return res;
}
int main() {
  cbuf = buf;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    rec[i].load(i);
  }
  sort(rec, rec + N);
  scanf("%d", &M);
  for (int i = 0; i < M * 4; ++i) {
    sp[i].init();
  }
  top = 0;
  for (int i = 0; i < M; ++i) {
    scanf("%d%d", x + i, y + i);
    coY[top++] = y[i];
  }
  coY[top++] = 0;
  coY[top++] = 10000000;
  sort(coY, coY + top);
  top = unique(coY, coY + top) - coY;
  for (int i = 0; i < M; ++i) {
    modify(1, 0, top - 1, x[i], y[i], i, 1);
  }
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < N; ++i) {
    int id = query(1, 0, top - 1, i);
    if (id != oo) {
      ans[id] = rec[i].lab;
      modify(1, 0, top - 1, x[id], y[id], id, -1);
    }
  }
  for (int i = 0; i < M; ++i) {
    printf("%d\n", ans[i] + 1);
  }
  return 0;
}
