#include <bits/stdc++.h>
const int N = 1000001;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  pair<int, int> a[n + 1];
  int mb[n + 1];
  memset(mb, 0, sizeof mb);
  vector<int> bids[n + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i].first >> a[i].second;
    mb[a[i].first] = max(mb[a[i].first], a[i].second);
    bids[a[i].first].push_back(a[i].second);
  }
  set<pair<int, int>> st;
  for (int i = 1; i < n + 1; i++) {
    st.insert(make_pair(mb[i], i));
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    vector<int> b(x);
    for (int i = 0; i < x; i++) {
      cin >> b[i];
      st.erase(make_pair(mb[b[i]], b[i]));
    }
    if (x == n) {
      cout << "0 0";
    } else {
      auto it = st.end();
      --it;
      auto f = *it;
      int winner = f.second;
      if (bids[winner].empty()) {
        cout << "0 0";
      } else {
        cout << winner << ' ';
        if (st.size() == 1) {
          cout << bids[winner][0];
        } else {
          --it;
          int ind =
              upper_bound(bids[winner].begin(), bids[winner].end(), it->first) -
              bids[winner].begin();
          cout << bids[winner][ind];
        }
      }
    }
    cout << '\n';
    for (int i = 0; i < x; i++) {
      st.insert(make_pair(mb[b[i]], b[i]));
    }
  }
}
