#include <bits/stdc++.h>
using namespace std;
const int maxn = 200050;
vector<int> p[maxn];
int ma[maxn];
int del[maxn];
set<pair<int, int> > s;
int main() {
  int n;
  scanf("%d", &n);
  memset(ma, 0, sizeof(ma));
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    p[x].push_back(y);
    ma[x] = max(ma[x], y);
  }
  for (int i = 1; i <= n; i++) {
    if (ma[i]) {
      s.insert(make_pair(ma[i], i));
    }
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int num;
    scanf("%d", &num);
    for (int i = 0; i < num; i++) {
      scanf("%d", &del[i]);
      if (ma[del[i]]) s.erase(make_pair(ma[del[i]], del[i]));
    }
    if (s.size() == 0) {
      printf("0 0\n");
    } else if (s.size() == 1) {
      printf("%d %d\n", s.begin()->second, p[s.begin()->second][0]);
    } else {
      set<pair<int, int> >::iterator it1;
      set<pair<int, int> >::iterator it2;
      it1 = s.end(), it2 = s.end();
      it1--;
      it2--, it2--;
      int x = it2->first;
      int index = it1->second;
      int it =
          upper_bound(p[index].begin(), p[index].end(), x) - p[index].begin();
      printf("%d %d\n", index, p[index][it]);
    }
    for (int i = 0; i < num; i++) {
      if (ma[del[i]]) s.insert(make_pair(ma[del[i]], del[i]));
    }
  }
  return 0;
}
