#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, q;
struct X {
  int id, val;
} s[maxn];
struct XX {
  int a, b;
  XX() {}
  XX(int A, int B) {
    a = A;
    b = B;
  }
  bool operator<(const XX &aa) const { return b > aa.b; }
};
XX fir, sec;
vector<int> v[maxn];
set<XX> h;
int tmp[maxn], mn[maxn], mx[maxn];
bool check(int x) {
  int tt = v[fir.a][x];
  if (s[tt].val < sec.b) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 200000; i++) mx[i] = 0, mn[i] = 2000000000;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &s[i].id, &s[i].val);
    v[s[i].id].push_back(i);
    mx[s[i].id] = max(mx[s[i].id], s[i].val);
    mn[s[i].id] = min(mn[s[i].id], s[i].val);
  }
  for (int i = 1; i <= 200000; i++) {
    if (mx[i] == 0) continue;
    h.insert(XX(i, mx[i]));
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) scanf("%d", &tmp[j]);
    for (int j = 1; j <= k; j++) {
      if (mx[tmp[j]] == 0) continue;
      h.erase(XX(tmp[j], mx[tmp[j]]));
    }
    if (h.size() == 0) {
      printf("0 0\n");
    } else if (h.size() == 1) {
      XX ans = *h.begin();
      printf("%d %d\n", ans.a, mn[ans.a]);
    } else {
      set<XX>::iterator iter;
      int cnt = 0;
      for (iter = h.begin(); iter != h.end(); iter++) {
        cnt++;
        if (cnt == 1)
          fir = *iter;
        else if (cnt == 2) {
          sec = *iter;
          break;
        }
      }
      int L = 0, R = v[fir.a].size() - 1;
      int ans;
      while (L <= R) {
        int mid = (L + R) / 2;
        if (check(mid))
          ans = mid, R = mid - 1;
        else
          L = mid + 1;
      }
      int tt = v[fir.a][ans];
      printf("%d %d\n", s[tt].id, s[tt].val);
    }
    for (int j = 1; j <= k; j++) {
      if (mx[tmp[j]] == 0) continue;
      h.insert(XX(tmp[j], mx[tmp[j]]));
    }
  }
  return 0;
}
