#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[200005];
vector<int> allbid[200005];
set<pair<int, int> > bidlist;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    p[a].first = -b, allbid[a].push_back(b), p[a].second = a;
  }
  for (int i = 1; i <= n; i++)
    if (allbid[i].size() != 0) bidlist.insert(p[i]);
  int q;
  scanf("%d", &q);
  while (q--) {
    int l;
    vector<int> lst;
    scanf("%d", &l);
    for (int i = 0; i < l; i++) {
      int x;
      scanf("%d", &x);
      lst.push_back(x);
      bidlist.erase(p[x]);
    }
    if (bidlist.size() == 0)
      printf("0 0\n");
    else if (bidlist.size() == 1)
      for (auto e : bidlist) printf("%d %d\n", e.second, allbid[e.second][0]);
    else {
      vector<pair<int, int> > buf;
      for (auto e : bidlist) {
        if (buf.size() == 2) break;
        buf.push_back(e);
      }
      auto v = upper_bound(allbid[buf[0].second].begin(),
                           allbid[buf[0].second].end(), -buf[1].first);
      printf("%d %d\n", buf[0].second,
             allbid[buf[0].second][v - allbid[buf[0].second].begin()]);
    }
    for (auto e : lst)
      if (allbid[e].size() != 0) bidlist.insert(p[e]);
  }
}
