#include <bits/stdc++.h>
using namespace std;
const int MAX = 200100;
int a[MAX], b[MAX], c[MAX];
int numType[MAX];
vector<int> f[MAX];
int n, q, k;
void process() {
  int M, L = 1, R = n, ans = -1;
  int tot;
  sort(c, c + k);
  while (L <= R) {
    M = (L + R) / 2;
    tot = 0;
    for (int i = 0; i < k; i++) {
      if (f[c[i]].size() && f[c[i]][f[c[i]].size() - 1] >= M) tot++;
    }
    if (numType[M] - tot == 1) {
      if (c[k - 1] < a[M] || (*lower_bound(c, c + k, a[M]) != a[M])) {
        ans = a[M];
        break;
      } else
        L = M + 1;
      continue;
    }
    if (numType[M] - tot <= 1)
      R = M - 1;
    else
      L = M + 1;
  }
  if (ans == -1) {
    cout << "0 0\n";
    return;
  }
  L = 0;
  R = f[ans].size() - 1;
  int res;
  while (L <= R) {
    M = (L + R) / 2;
    tot = 0;
    for (int i = 0; i < k; i++) {
      if (f[c[i]].size() && f[c[i]][f[c[i]].size() - 1] >= f[ans][M]) tot++;
    }
    if (numType[f[ans][M]] - tot == 1) res = M;
    if (numType[f[ans][M]] - tot <= 1)
      R = M - 1;
    else
      L = M + 1;
  }
  cout << ans << " " << b[f[ans][res]] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    f[a[i]].push_back(i);
  }
  memset(c, 0, sizeof(c));
  for (int i = n; i > 0; i--)
    if (!c[a[i]]) {
      numType[i] = numType[i + 1] + 1;
      c[a[i]] = 1;
    } else
      numType[i] = numType[i + 1];
  cin >> q;
  while (q--) {
    cin >> k;
    for (int i = 0; i < k; i++) cin >> c[i];
    process();
  }
  return 0;
}
