#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, b[N], i, p, q, k, absent[N], winner;
map<int, int> mb;
vector<int> bets[N];
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> p >> b[i];
    bets[p].push_back(i);
  }
  for (i = 1; i <= n; ++i)
    if (!bets[i].empty()) mb[bets[i].back()] = i;
  cin >> q;
  for (; q; --q) {
    cin >> k;
    for (i = 0; i < k; ++i) {
      cin >> absent[i];
      if (bets[absent[i]].empty())
        --i, --k;
      else
        mb.erase(bets[absent[i]].back());
    }
    if (mb.empty())
      cout << "0 0\n";
    else {
      winner = mb.rbegin()->second;
      mb.erase(mb.rbegin()->first);
      if (mb.empty())
        cout << winner << " " << b[bets[winner][0]] << "\n";
      else
        cout << winner << " "
             << b[*upper_bound(bets[winner].begin(), bets[winner].end(),
                               mb.rbegin()->first)]
             << "\n";
      mb[bets[winner].back()] = winner;
    }
    for (i = 0; i < k; ++i) mb[bets[absent[i]].back()] = absent[i];
  }
  return 0;
}
