#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i, j, k, l, m, x, z, y, t, x1, y1, z1, f, q;
  cin >> n;
  set<pair<long long, long long> > s;
  set<pair<long long, long long> >::iterator it;
  map<long long, long long> mp1, mp2;
  for (i = 1; i <= n; i++) {
    mp1[i] = -1;
    mp2[i] = 1000000000000;
  }
  vector<long long> value[n + 1];
  vector<long long>::iterator ite;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    value[x].push_back(y);
    if (y >= mp1[x]) {
      s.erase(make_pair(mp1[x], x));
      s.insert(make_pair(y, x));
      mp1[x] = y;
    }
    mp2[x] = min(mp2[x], y);
  }
  cin >> q;
  while (q--) {
    cin >> m;
    vector<long long> v;
    for (i = 0; i < m; i++) {
      cin >> x;
      if (mp1[x] != -1) {
        v.push_back(x);
        s.erase(make_pair(mp1[x], x));
      }
    }
    if (s.size() == 0) {
      cout << "0 0"
           << "\n";
    } else {
      if (s.size() > 1) {
        it = s.end();
        it--;
        y = it->second;
        it--;
        x = it->first;
        ite = upper_bound(value[y].begin(), value[y].end(), x);
        long long in = ite - value[y].begin();
        z = value[y][in];
        cout << y << " " << z << "\n";
      } else {
        it = s.begin();
        cout << it->second << " " << mp2[it->second] << "\n";
      }
    }
    for (i = 0; i < v.size(); i++) {
      s.insert(make_pair(mp1[v[i]], v[i]));
    }
    v.clear();
  }
  return 0;
}
