#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const int inf = 0x3f3f3f3f;
vector<int> ve[maxn];
int a[maxn], c[maxn];
struct node {
  int pos, val;
} nod[maxn];
bool cmp(node a, node b) { return a.val < b.val; }
bool cmp1(int x, int y) { return nod[a[x]].val > nod[a[y]].val; }
int main() {
  int n, q, k, x, y;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) {
    ve[i].clear();
    nod[i].val = 0;
    nod[i].pos = 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    ve[x].push_back(y);
    nod[x].pos = x;
    nod[x].val = max(nod[x].val, y);
  }
  sort(nod + 1, nod + 1 + n, cmp);
  for (int i = 1; i <= n; i++) a[nod[i].pos] = i;
  scanf("%d", &q);
  int ans, res;
  while (q--) {
    int max1 = nod[n].val, pos1 = nod[n].pos;
    int max2 = nod[n - 1].val, pos2 = nod[n - 1].pos, s, j = n - 2;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) scanf("%d", &c[i]);
    sort(c, c + k, cmp1);
    for (int i = 0; i < k; i++) {
      if (c[i] == pos1) {
        max1 = max2;
        pos1 = pos2;
        max2 = nod[j].val;
        pos2 = nod[j--].pos;
      } else if (c[i] == pos2) {
        max2 = nod[j].val;
        pos2 = nod[j--].pos;
      }
    }
    if (max1 == 0)
      ans = 0, res = 0;
    else {
      int l = 0, r = ve[pos1].size(), mid;
      while (l < r) {
        mid = l + (r - l) / 2;
        if (max2 <= ve[pos1][mid])
          r = mid;
        else
          l = mid + 1;
      }
      ans = pos1;
      res = ve[pos1][l];
    }
    printf("%d %d\n", ans, res);
  }
  return 0;
}
