#include <bits/stdc++.h>
using namespace std;
vector<int> a[200005];
set<pair<int, int>> s;
int n, m, x, y, t, mmax[200005], vis[200005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    mmax[x] = max(mmax[x], y);
    vis[x] = 1;
    a[x].push_back(y);
  }
  for (int i = 1; i <= n; i++)
    if (vis[i]) s.insert(make_pair(mmax[i], i));
  cin >> m;
  while (m--) {
    cin >> t;
    vector<int> d;
    for (int i = 1; i <= t; i++) {
      cin >> x;
      if (vis[x]) {
        s.erase(make_pair(mmax[x], x));
        d.push_back(x);
      }
    }
    if (s.size() == 0)
      cout << 0 << ' ' << 0 << endl;
    else if (s.size() == 1) {
      auto v = s.begin();
      cout << v->second << ' ' << a[v->second][0] << endl;
    } else {
      auto n1 = s.end(), n2 = s.end();
      n1--;
      n2--;
      n2--;
      auto val =
          upper_bound(a[n1->second].begin(), a[n1->second].end(), n2->first);
      cout << n1->second << ' ' << *val << endl;
    }
    for (int i = 0; i < d.size(); i++) s.insert(make_pair(mmax[d[i]], d[i]));
  }
  return 0;
}
