#include <bits/stdc++.h>
using namespace std;
vector<int> val;
const int maxn = 100005;
const int INF = 0x3f3f3f3f;
const int maxBST = 4000005;
struct BST {
  struct node {
    int m, size, num;
    pair<int, int> s;
    node *ch[2], *par;
    static node *nil, nil_ins;
    node() {
      ch[0] = ch[1] = par = node::nil;
      size = 0;
      m = INF;
      num = INF;
      s = make_pair(-INF, INF);
    }
  } * root;
  static node tree[maxBST], *Tptr;
  void update(node *pos) {
    pos->size = pos->ch[1]->size + pos->ch[0]->size + 1;
    pos->m = min(min(pos->ch[1]->m, pos->ch[0]->m), pos->num);
  }
  void clear() {
    root = Tptr++;
    (root->ch[1] = Tptr++)->par = root;
    root->s.first = -INF;
    root->ch[1]->s.first = INF;
    update(root->ch[1]);
    update(root);
  }
  void rot(node *pos, int t) {
    node *tptr = pos->ch[t], *tmp;
    tmp = pos->ch[t] = tptr->ch[!t];
    if (tmp != node::nil) tmp->par = pos;
    tptr->ch[!t] = pos;
    tmp = tptr->par = pos->par;
    pos->par = tptr;
    if (tmp != node::nil)
      tmp->ch[tmp->ch[1] == pos] = tptr;
    else
      root = tptr;
    update(pos);
  }
  void splay(node *pos, node *&des) {
    node *p, *g;
    bool t1, t2;
    while ((p = pos->par) != des && pos != des) {
      g = p->par;
      t1 = p->ch[1] == pos;
      t2 = g->ch[1] == p;
      if (t1 == t2) {
        rot(g, t2);
        rot(p, t1);
      } else {
        rot(p, t1);
        rot(g, t2);
      }
    }
    if (pos != des) rot(des, des->ch[1] == pos);
    update(des);
  }
  void ins(int y, int d) {
    node *tptr = Tptr++;
    tptr->num = d;
    tptr->s = make_pair(y, d);
    tptr->size = 1;
    update(tptr);
    node *pos = root;
    while (1) {
      pos->size++;
      if (pos->ch[pos->s < tptr->s] == node::nil) {
        (pos->ch[pos->s < tptr->s] = tptr)->par = pos;
        splay(tptr, root);
        break;
      } else
        pos = pos->ch[pos->s < tptr->s];
    }
  }
  node *findkth(int k) {
    node *pos = root;
    int l;
    bool f;
    while ((l = pos->ch[0]->size + 1) != k) {
      f = l < k;
      pos = pos->ch[f];
      if (f) k -= l;
    }
    return pos;
  }
  int findlower(int y) {
    int ret = 0;
    node *pos = root;
    while (pos != node::nil) {
      if (pos->s.first < y) {
        ret += pos->ch[0]->size + 1;
        pos = pos->ch[1];
      } else {
        pos = pos->ch[0];
      }
    }
    return ret + 1;
  }
  int ask(int l, int r) {
    int a = findlower(l);
    int b = findlower(r + 1) - 1;
    splay(findkth(2), root);
    splay(findkth(a - 1), root);
    splay(findkth(b + 1), root->ch[1]);
    return root->ch[1]->ch[0]->m;
  }
  int findk(pair<int, int> p) {
    node *pos = root;
    int ret = 0;
    bool f;
    while (pos->s != p) {
      f = pos->s < p;
      if (f) ret += pos->ch[0]->size + 1;
      pos = pos->ch[f];
    }
    return ret + pos->ch[0]->size + 1;
  }
  void del(int y, int p) {
    p = findk(make_pair(y, p));
    splay(findkth(p - 1), root);
    splay(findkth(p + 1), root->ch[1]);
    root->ch[1]->ch[0] = node::nil;
    update(root->ch[1]);
    update(root);
  }
};
BST::node BST::node::nil_ins;
BST::node *BST::node::nil = &BST::node::nil_ins;
BST::node BST::tree[maxBST];
BST::node *BST::Tptr = BST::tree;
struct SEG {
  struct node {
    int l, r;
    BST bst;
    node *lc, *rc;
  } * root;
  node tree[maxn * 12], *Tptr;
  SEG() { Tptr = tree; }
  node *mktree(int l, int r) {
    node *tptr = Tptr++;
    tptr->l = l;
    tptr->r = r;
    tptr->bst.clear();
    if (l == r) return tptr;
    tptr->lc = mktree(l, (l + r) >> 1);
    tptr->rc = mktree(1 + ((l + r) >> 1), r);
    return tptr;
  }
  void mktree(int n) { root = mktree(1, n); }
  int ask(int x1, int x2, int y1, int y2, node *tptr) {
    if (x1 <= tptr->l && x2 >= tptr->r) {
      return tptr->bst.ask(y1, y2);
    }
    return min((x1 <= tptr->lc->r ? ask(x1, x2, y1, y2, tptr->lc) : INF),
               (x2 >= tptr->rc->l ? ask(x1, x2, y1, y2, tptr->rc) : INF));
  }
  int ask(int x1, int x2, int y1, int y2) { return ask(x1, x2, y1, y2, root); }
  void del(int x, int y, int d, node *tptr) {
    if (tptr->l <= x && tptr->r >= x) {
      tptr->bst.del(y, d);
    }
    if (tptr->l == tptr->r) return;
    if (x <= tptr->lc->r) del(x, y, d, tptr->lc);
    if (x >= tptr->rc->l) del(x, y, d, tptr->rc);
  }
  void del(int x1, int y1, int d) { del(x1, y1, d, root); }
  void ins(int x, int y, int d, node *tptr) {
    if (tptr->l <= x && tptr->r >= x) {
      tptr->bst.ins(y, d);
    }
    if (tptr->l == tptr->r) return;
    if (x <= tptr->lc->r) ins(x, y, d, tptr->lc);
    if (x >= tptr->rc->l) ins(x, y, d, tptr->rc);
  }
  void ins(int x, int y, int d) { ins(x, y, d, root); }
} G;
int getid(int x) {
  return lower_bound(val.begin(), val.end(), x) - val.begin() + 1;
}
struct MAR {
  int x1, x2, y1, y2;
  int z;
  int id;
  void load(int v) {
    scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
    scanf("%d", &z);
    id = v;
  }
  bool operator<(const MAR &o) const { return z < o.z; }
} Ret[maxn];
int n, m;
int out[maxn];
struct Point {
  int x, y;
  void load() {
    scanf("%d%d", &x, &y);
    val.push_back(x);
  }
} P[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    Ret[i].load(i);
  }
  sort(Ret, Ret + n);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    P[i].load();
  }
  val.push_back(0);
  val.push_back(INF);
  sort(val.begin(), val.end());
  val.resize(distance(val.begin(), unique(val.begin(), val.end())));
  G.mktree(val.size());
  for (int i = 0; i < m; ++i) {
    G.ins(getid(P[i].x), P[i].y, i + 1);
  }
  for (int i = 0; i < n; ++i) {
    int t =
        G.ask(getid(Ret[i].x1), getid(Ret[i].x2 + 1) - 1, Ret[i].y1, Ret[i].y2);
    if (t == INF) continue;
    out[t] = Ret[i].id + 1;
    G.del(getid(P[t - 1].x), P[t - 1].y, t);
  }
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", out[i]);
  }
}
