#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s;
vector<vector<int> > v;
vector<int> b;
int bid[200005];
int main() {
  int n, k, q, x, y;
  cin >> n;
  v.resize(n + 1);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    bid[x] = y;
    v[x].push_back(y);
  }
  for (int i = 1; i <= n; i++)
    if (bid[i]) s.insert(make_pair(bid[i], i));
  cin >> q;
  while (q--) {
    b.clear();
    scanf("%d", &k);
    while (k--) {
      scanf("%d", &x);
      if (s.find(make_pair(bid[x], x)) == s.end()) continue;
      s.erase(make_pair(bid[x], x));
      b.push_back(x);
    }
    if (s.empty())
      printf("0 0\n");
    else {
      set<pair<int, int> >::iterator it = s.end();
      it--;
      if (s.size() == 1)
        printf("%d %d\n", it->second, v[it->second][0]);
      else {
        set<pair<int, int> >::iterator itt = it;
        itt--;
        int temp = bid[itt->second];
        printf("%d %d\n", it->second,
               v[it->second]
                [upper_bound(v[it->second].begin(), v[it->second].end(), temp) -
                 v[it->second].begin()]);
      }
    }
    for (int i = 0; i < b.size(); i++) s.insert(make_pair(bid[b[i]], b[i]));
  }
  return 0;
}
