#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 2e9;
const int mod = 1e9 + 7;
const long long INF = 2e18;
int n, q, a[N], b[N], res;
vector<int> g[N];
set<pair<int, int> > s;
char u[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0, x, y; i < n; ++i) {
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    u[a[i]] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (u[i]) {
      s.insert(make_pair(g[i].back(), i));
    }
  }
  cin >> q;
  for (int qq = 0, k; qq < q; ++qq) {
    vector<int> v;
    cin >> k;
    for (int kk = 0, x; kk < k; ++kk) {
      cin >> x;
      if (!u[x]) {
        continue;
      }
      v.push_back(x);
      s.erase(make_pair(g[x].back(), x));
    }
    if (s.empty()) {
      cout << "0 0\n";
    } else {
      if (s.size() == 1) {
        res = s.begin()->second;
        cout << res << ' ' << g[res][0] << '\n';
      } else {
        set<pair<int, int> >::iterator it = s.end();
        --it;
        int m1 = it->second;
        --it;
        int m2 = it->second;
        int cur = it->first;
        cout << m1 << ' '
             << g[m1]
                 [upper_bound(g[m1].begin(), g[m1].end(), cur) - g[m1].begin()]
             << '\n';
      }
    }
    for (int i = 0; i < v.size(); ++i) {
      s.insert(make_pair(g[v[i]].back(), v[i]));
    }
  }
  return 0;
}
