#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll inf = 1;
const ll mod = 1E9;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int> > bids(n + 1, vector<int>());
  vector<int> highestBid(n + 1, 0);
  for (int i = 0; i < n; i++) {
    int id, amt;
    cin >> id >> amt;
    bids[id].push_back(amt);
    highestBid[id] = max(highestBid[id], amt);
  }
  set<pii> ms;
  for (int i = 1; i <= n; i++)
    if (highestBid[i]) {
      ms.insert({highestBid[i], i});
    }
  int q;
  cin >> q;
  for (int cs = 0; cs < q; cs++) {
    int m;
    cin >> m;
    vector<int> fire(m);
    for (auto &x : fire) {
      cin >> x;
      if (highestBid[x]) {
        ms.erase({highestBid[x], x});
      }
    }
    if ((int)ms.size() == 0) {
      cout << 0 << ' ' << 0 << endl;
    } else if ((int)ms.size() == 1) {
      cout << ms.begin()->second << ' ' << bids[ms.begin()->second][0] << endl;
    } else {
      int best = prev(ms.end())->second,
          secondBest = prev(prev(ms.end()))->second;
      int lo = 0, hi = (int)bids[best].size() - 1, ans;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (bids[best][mid] > highestBid[secondBest]) {
          ans = bids[best][mid];
          hi = mid - 1;
        } else {
          lo = mid + 1;
        }
      }
      cout << best << ' ' << ans << endl;
    }
    for (auto &x : fire) {
      if (highestBid[x]) {
        ms.insert({highestBid[x], x});
      }
    }
  }
  return 0;
}
