#include <bits/stdc++.h>
using namespace std;
set<pair<int, int>> S;
map<int, int> M;
map<int, vector<int>> V;
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) {
    S.insert(pair<int, int>(0, i));
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    V[x].push_back(y);
    S.erase(pair<int, int>(M[x], x));
    M[x] = y;
    S.insert(pair<int, int>(y, x));
  }
  scanf("%d", &q);
  while (q--) {
    set<pair<int, int>> T;
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      T.insert(pair<int, int>(M[x], x));
      S.erase(pair<int, int>(M[x], x));
    }
    auto it = S.end();
    it--;
    int f = (*it).second;
    if (M[f] != 0) {
      S.erase(pair<int, int>(M[f], f));
      T.insert(pair<int, int>(M[f], f));
      it = S.end();
      it--;
      int v = ((*it).first);
      printf("%d %d\n", f, *lower_bound(V[f].begin(), V[f].end(), v));
    } else {
      printf("0 0\n");
    }
    for (auto p : T) {
      S.insert(p);
    }
  }
}
