#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> pmax, maxp;
  vector<int> g[n + 2];
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    if (pmax.find(a) == pmax.end())
      pmax[a] = b;
    else
      pmax[a] = max(pmax[a], b);
  }
  for (auto i = pmax.begin(); i != pmax.end(); i++) {
    maxp[i->second] = i->first;
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    vector<pair<int, int> > maxpaux;
    for (int i = 0; i < k; i++) {
      int l;
      cin >> l;
      if (pmax.find(l) == pmax.end()) continue;
      maxpaux.push_back(pair<int, int>(pmax[l], l));
      maxp.erase(pmax[l]);
    }
    if (maxp.empty()) {
      cout << 0 << ' ' << 0 << '\n';
    } else if (maxp.size() == 1) {
      cout << maxp.begin()->second << ' ' << g[maxp.begin()->second][0] << '\n';
    } else {
      auto en = maxp.end();
      en--;
      int personmax = en->second;
      cout << personmax << ' ';
      en--;
      int secondperson = en->second;
      int pos = upper_bound(g[personmax].begin(), g[personmax].end(),
                            pmax[secondperson]) -
                g[personmax].begin();
      int answer = g[personmax][pos];
      cout << answer << '\n';
    }
    for (int i = 0; i < maxpaux.size(); i++) {
      maxp[maxpaux[i].first] = maxpaux[i].second;
    }
  }
  return 0;
}
