#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 4;
vector<long long int> bidl[mx];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i;
  cin >> n;
  int u;
  long long int v;
  for (i = 0; i < n; i++) {
    cin >> u >> v;
    bidl[u].push_back(v);
  }
  map<long long int, int> mp;
  map<int, long long int> rmp;
  set<long long int> x;
  for (i = 1; i <= n; i++) {
    if (bidl[i].size() != 0) {
      x.insert(bidl[i][bidl[i].size() - 1]);
      mp[i] = bidl[i][bidl[i].size() - 1];
      rmp[bidl[i][bidl[i].size() - 1]] = i;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int k, ll;
    cin >> k;
    vector<int> h;
    for (i = 0; i < k; i++) {
      cin >> ll;
      if (bidl[ll].size() != 0) {
        h.push_back(ll);
        long long int y = mp[ll];
        x.erase(x.find(y));
      }
    }
    if (x.size() == 0) {
      cout << "0"
           << " "
           << "0"
           << "\n";
    } else if (x.size() == 1) {
      long long int o = *x.rbegin();
      int win = rmp[o];
      cout << win << " " << bidl[win][0] << "\n";
    } else {
      long long int o = *x.rbegin();
      int win = rmp[o];
      set<long long int>::iterator it = x.end();
      it--;
      x.erase(it);
      long long int pp = *x.rbegin();
      x.insert(o);
      int jj = upper_bound(bidl[win].begin(), bidl[win].end(), pp) -
               bidl[win].begin();
      cout << win << " " << bidl[win][jj] << "\n";
    }
    for (i = 0; i < h.size(); i++) {
      x.insert(mp[h[i]]);
    }
  }
}
