#include <bits/stdc++.h>
using namespace std;
const int M = 200009;
int n, q, k, x, s;
vector<pair<int, int> > p;
vector<vector<int> > pb;
set<int> last;
void solve() {
  cin >> n;
  p.resize(n + 1);
  pb.resize(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> x >> s;
    p[i] = {x, s};
    pb[x].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (pb[i].size() > 0) last.insert(pb[i].back());
  last.insert(-1);
  for (cin >> q; q; q--) {
    cin >> k;
    vector<int> esc(k);
    for (int i = 0; i < k; i++) {
      cin >> esc[i];
      if (pb[esc[i]].size() > 0) last.erase(pb[esc[i]].back());
    }
    pair<int, int> ans = {0, 0};
    if (last.size() != 1) {
      auto iw = --last.end();
      int win = p[*iw].first;
      auto bwin = *upper_bound(pb[win].begin(), pb[win].end(), *--iw);
      ans = {win, p[bwin].second};
    }
    cout << ans.first << " " << ans.second << endl;
    for (int i = 0; i < k; i++)
      if (pb[esc[i]].size() > 0) last.insert(pb[esc[i]].back());
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
}
