#include <bits/stdc++.h>
using namespace std;
const int step = 500;
struct st {
  int x[2], y[2], z;
  int ind;
  void read() { scanf("%d%d%d%d%d", &x[0], &x[1], &y[0], &y[1], &z); }
  bool operator<(const st &s) const { return z < s.z; }
};
int n, m;
st a[1 << 17];
bool used[1 << 17];
int cnt;
const int LEV = 11;
pair<int, int> **v[100000 / step + 1][LEV];
pair<int, int> **buf[100000 / step + 1][LEV];
int *buflen[100000 / step + 1][LEV];
int *vlen[100000 / step + 1][LEV];
vector<int> c[100000 / step + 1];
map<int, int> Map[100000 / step + 1];
pair<int, int> t[5000];
void gen(int ind, int s, int f) {
  c[ind].clear();
  for (int i = s; i < f; ++i)
    if (!used[i]) {
      c[ind].push_back(a[i].x[0]);
      c[ind].push_back(a[i].x[1]);
      c[ind].push_back(a[i].x[0] - 1);
      c[ind].push_back(a[i].x[1] - 1);
    }
  sort(c[ind].begin(), c[ind].end());
  c[ind].erase(unique(c[ind].begin(), c[ind].end()), c[ind].end());
  for (int i = 0; i < LEV; ++i) {
    v[ind][i] = new pair<int, int> *[((int)c[ind].size() >> i) + 1];
    buf[ind][i] = new pair<int, int> *[((int)c[ind].size() >> i) + 1];
    vlen[ind][i] = new int[((int)c[ind].size() >> i) + 1];
    buflen[ind][i] = new int[((int)c[ind].size() >> i) + 1];
    for (int j = 0; j < ((int)c[ind].size() >> i) + 1; ++j) vlen[ind][i][j] = 0;
  }
  for (int i = 0; i < (int)c[ind].size(); ++i) Map[ind][c[ind][i]] = i;
  for (int i = s; i < f; ++i)
    if (!used[i]) {
      int si = Map[ind][a[i].x[0]];
      int fi = Map[ind][a[i].x[1]];
      int L = 0;
      while (si <= fi) {
        while (!(si & (1 << L)) && si + (1 << (L + 1)) <= fi + 1) ++L;
        while (si + (1 << L) > fi + 1) --L;
        ++vlen[ind][L][si >> L];
        si += 1 << L;
      }
    }
  for (int i = 0; i < LEV; ++i) {
    int tmp = ((int)c[ind].size() >> i) + 1;
    for (int j = 0; j < tmp; ++j) {
      v[ind][i][j] = new pair<int, int>[vlen[ind][i][j]];
      buf[ind][i][j] = new pair<int, int>[vlen[ind][i][j]];
      vlen[ind][i][j] = 0;
      buflen[ind][i][j] = 0;
    }
  }
  for (int i = s; i < f; ++i)
    if (!used[i]) {
      int si = Map[ind][a[i].x[0]];
      int fi = Map[ind][a[i].x[1]];
      int L = 0;
      while (si <= fi) {
        while (!(si & (1 << L)) && si + (1 << (L + 1)) <= fi + 1) ++L;
        while (si + (1 << L) > fi + 1) --L;
        v[ind][L][si >> L][vlen[ind][L][si >> L]++] =
            make_pair(a[i].y[0], a[i].y[1]);
        si += 1 << L;
      }
    }
  for (int i = 0; i < LEV; ++i) {
    int tmp = ((int)c[ind].size() >> i) + 1;
    for (int j = 0; j < tmp; ++j) {
      if (vlen[ind][i][j] == 0) continue;
      sort(v[ind][i][j], v[ind][i][j] + vlen[ind][i][j]);
      for (int k = 0; k < vlen[ind][i][j]; ++k)
        buf[ind][i][j][k] = v[ind][i][j][k];
      buflen[ind][i][j] = vlen[ind][i][j];
      int tlen = 1;
      t[0] = v[ind][i][j][0];
      for (int k = 1; k < vlen[ind][i][j]; ++k) {
        if (v[ind][i][j][k].first <= t[tlen - 1].second)
          t[tlen - 1].second = max(t[tlen - 1].second, v[ind][i][j][k].second);
        else
          t[tlen++] = v[ind][i][j][k];
      }
      for (int k = 0; k < tlen; ++k) v[ind][i][j][k] = t[k];
      vlen[ind][i][j] = tlen;
    }
  }
}
vector<int> r[LEV];
void gen_new(int ind, int s, int f, int x) {
  for (int i = 0; i < LEV; ++i) r[i].clear();
  for (int i = x; i < x + 1; ++i) {
    int si = Map[ind][a[i].x[0]];
    int fi = Map[ind][a[i].x[1]];
    int L = 0;
    while (si <= fi) {
      while (!(si & (1 << L)) && si + (1 << (L + 1)) <= fi + 1) ++L;
      while (si + (1 << L) > fi + 1) --L;
      int pos = find(buf[ind][L][si >> L],
                     buf[ind][L][si >> L] + buflen[ind][L][si >> L],
                     make_pair(a[i].y[0], a[i].y[1])) -
                buf[ind][L][si >> L];
      buf[ind][L][si >> L][pos].first = -1;
      r[L].push_back(si >> L);
      si += 1 << L;
    }
  }
  for (int i = 0; i < LEV; ++i) {
    for (int j_ = 0; j_ < (int)r[i].size(); ++j_) {
      int j = r[i][j_];
      if (buflen[ind][i][j] == 0) {
        vlen[ind][i][j] = 0;
        continue;
      }
      int tlen = 0;
      for (int k = 0; k < buflen[ind][i][j]; ++k) {
        if (buf[ind][i][j][k].first == -1) continue;
        if (tlen && buf[ind][i][j][k].first <= t[tlen - 1].second)
          t[tlen - 1].second =
              max(t[tlen - 1].second, buf[ind][i][j][k].second);
        else
          t[tlen++] = buf[ind][i][j][k];
      }
      for (int k = 0; k < tlen; ++k) v[ind][i][j][k] = t[k];
      vlen[ind][i][j] = tlen;
    }
  }
}
bool check(int ind, int s, int f, int x, int y) {
  vector<int>::iterator it = lower_bound(c[ind].begin(), c[ind].end(), x);
  if (it == c[ind].end()) return false;
  int xx = x;
  x = it - c[ind].begin();
  bool found = false;
  for (int i = 0; i < LEV; ++i) {
    int pos = x >> i;
    int Min = 0;
    int Max = vlen[ind][i][pos] - 1;
    if (Max == -1) continue;
    int Mid;
    do {
      Mid = (Min + Max) >> 1;
      if (v[ind][i][pos][Mid].first > y)
        Max = Mid;
      else
        Min = Mid;
    } while (Max - Min > 1);
    if (v[ind][i][pos][Min].first <= y && v[ind][i][pos][Min].second >= y) {
      found = true;
      break;
    }
    if (v[ind][i][pos][Max].first <= y && v[ind][i][pos][Max].second >= y) {
      found = true;
      break;
    }
  }
  if (!found) return false;
  x = xx;
  for (int i = s; i < f; ++i)
    if (!used[i] && a[i].x[0] <= x && x <= a[i].x[1] && a[i].y[0] <= y &&
        y <= a[i].y[1]) {
      printf("%d\n", a[i].ind);
      used[i] = true;
      gen_new(ind, s, f, i);
      return true;
    }
  throw -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    a[i].read();
    a[i].ind = i + 1;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i += step) gen(cnt++, i, min(i + step, n));
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    cnt = 0;
    bool found = false;
    for (int i = 0; i < n; i += step) {
      if (check(cnt++, i, min(i + step, n), x, y)) {
        found = true;
        break;
      }
    }
    if (!found) puts("0");
  }
  return 0;
}
