#include <bits/stdc++.h>
using namespace std;
int n, x, y, q, m;
vector<int> v[200005], ok;
struct cmp {
  bool operator()(const int& a, const int& b) const {
    return v[a].back() > v[b].back();
  }
};
set<int, cmp> s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  v[0].push_back(-1);
  s.insert(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    if (v[x].size() == 1) ok.push_back(x);
  }
  for (int i = 0; i < ok.size(); i++) s.insert(ok[i]);
  cin >> q;
  for (; q; q--) {
    cin >> m;
    int a[m + 1];
    for (int i = 1; i <= m; i++) {
      cin >> a[i];
      if (v[a[i]].size()) s.erase(s.find(a[i]));
    }
    int mx = *(s.begin());
    s.erase(s.begin());
    if (mx) {
      int bas = 0, son = v[mx].size() - 1;
      while (bas <= son) {
        int orta = (bas + son) >> 1;
        if (v[mx][orta] < v[*s.begin()].back())
          bas = orta + 1;
        else
          son = orta - 1;
      }
      cout << mx << " " << v[mx][bas] << endl;
    } else
      cout << "0 0\n";
    s.insert(mx);
    for (int i = 1; i <= m; i++) {
      if (v[a[i]].size()) s.insert(a[i]);
    }
  }
}
