#include <bits/stdc++.h>
using namespace std;
const int M = 200179;
int n, q, k, t;
int p[M], b[M];
vector<int> pb[M];
set<int> last;
int main() {
  scanf("%d", &n);
  for (int t = 0; t < n; t++) {
    scanf("%d%d", &p[t], &b[t]);
    pb[p[t]].push_back(t);
  }
  last.insert(-1);
  for (int p = 1; p <= n; p++)
    if (pb[p].size()) last.insert(*pb[p].rbegin());
  for (scanf("%d", &q); q; q--) {
    scanf("%d", &k);
    vector<int> esc(k);
    for (int i = 0; i < k; i++)
      if (scanf("%d", &esc[i]), pb[esc[i]].size())
        last.erase(*pb[esc[i]].rbegin());
    pair<int, int> ans = {0, 0};
    if (last.size() > 1) {
      auto iw = last.rbegin();
      int win = p[*iw];
      ans = {win, b[*upper_bound(pb[win].begin(), pb[win].end(), *++iw)]};
    }
    cout << ans.first << " " << ans.second << endl;
    for (int i = 0; i < k; i++)
      if (pb[esc[i]].size()) last.insert(*pb[esc[i]].rbegin());
  }
}
