#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 111;
int last[maxn], n, k, a[maxn], b[maxn], c[maxn];
set<pair<int, int> > q;
vector<int> pos[maxn];
bool was[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    q.erase(make_pair(-last[a[i]], a[i]));
    last[a[i]] = i;
    q.insert(make_pair(-i, a[i]));
    was[a[i]] = true;
    pos[a[i]].push_back(i);
  }
  cin >> k;
  while (k--) {
    int m;
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%d", &c[i]);
      if (was[c[i]]) q.erase(make_pair(-last[c[i]], c[i]));
    }
    if (q.empty())
      printf("0 0\n");
    else {
      pair<int, int> x = *q.begin();
      q.erase(x);
      if (q.empty())
        printf("%d %d\n", x.second, b[pos[x.second][0]]);
      else {
        pair<int, int> z = *q.begin();
        int t = -z.first;
        int valx = x.second;
        int j = (lower_bound(pos[valx].begin(), pos[valx].end(), t) -
                 pos[valx].begin());
        j = pos[valx][j];
        printf("%d %d\n", valx, b[j]);
      }
      q.insert(x);
    }
    for (int i = 0; i < m; i++)
      if (was[c[i]]) q.insert(make_pair(-last[c[i]], c[i]));
  }
  return 0;
}
