#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f;
const long long INFL = (long long)1E18;
const int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
vector<vector<int> > all;
set<int> ss;
set<int> tt;
map<int, int> mm;
vector<int> maxv;
int main() {
  int n;
  cin >> n;
  all.assign(n, vector<int>(0, 0));
  maxv.assign(n, -1);
  for (int i = (0); i < (n); i++) {
    int a, val;
    cin >> a >> val;
    all[a - 1].push_back(val);
    mm[val] = a - 1;
    maxv[a - 1] = val;
  }
  for (int i = (0); i < (n); i++)
    if (maxv[i] != -1) {
      ss.insert(maxv[i]);
    }
  int q;
  cin >> q;
  for (int i = (0); i < (q); i++) {
    int num = 0;
    cin >> num;
    for (int j = (0); j < (num); j++) {
      int now;
      cin >> now;
      now--;
      int maxp = maxv[now];
      if (maxp != -1) {
        tt.insert(maxp);
        ss.erase(maxp);
      }
    }
    if (ss.size() == 0) {
      cout << 0 << " " << 0 << endl;
    } else {
      int maxval = *ss.rbegin();
      int maxidx = mm[maxval];
      if (ss.size() > 1) {
        int secondmax = *(next(ss.rbegin()));
        int secondmaxi = mm[secondmax];
        cout << maxidx + 1 << " "
             << *upper_bound(all[maxidx].begin(), all[maxidx].end(), secondmax)
             << endl;
      } else {
        cout << maxidx + 1 << " " << all[maxidx][0] << endl;
      }
    }
    while (!tt.empty()) {
      ss.insert(*tt.begin());
      tt.erase(tt.begin());
    }
  }
  return 0;
}
