#include <bits/stdc++.h>
using namespace std;
struct point {
  int x1, x2, y1, y2, id, z;
};
int n, m;
int pre[100050], suc[100050];
point a[100050];
bool cmp(point x, point y) { return x.z < y.z ? true : false; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d%d", &a[i].x1, &a[i].x2, &a[i].y1, &a[i].y2, &a[i].z);
    a[i].id = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    pre[i] = i - 1;
    suc[i] = i + 1;
  }
  scanf("%d", &m);
  int x, y, first = 1, j;
  for (; m--;) {
    scanf("%d%d", &x, &y);
    for (j = first; j <= n; j = suc[j]) {
      if (x >= a[j].x1 && x <= a[j].x2 && y <= a[j].y2 && y >= a[j].y1) break;
    }
    if (j > n) {
      printf("0\n");
      continue;
    }
    printf("%d\n", a[j].id);
    if (j == first) {
      first = suc[j];
      continue;
    }
    pre[suc[j]] = pre[j];
    suc[pre[j]] = suc[j];
  }
  return 0;
}
