#include <bits/stdc++.h>
using namespace std;
vector<int> ss[200005];
pair<int, int> mx[200005];
vector<int> qq;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 200005; i++) {
    mx[i] = make_pair(1e9 + 5, -1);
  }
  int nnnn = 0;
  for (int i = 0; i < n; i++) {
    int nn, s;
    scanf("%d %d", &nn, &s);
    if (ss[nn].size() == 0) {
      nnnn++;
    }
    mx[nn] = make_pair(s, nn);
    ss[nn].push_back(s);
  }
  sort(mx, mx + 200005);
  qq.reserve(200005);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    qq.clear();
    for (int j = 0; j < k; j++) {
      int qqq;
      scanf("%d", &qqq);
      qq.push_back(qqq);
    }
    sort(qq.begin(), qq.end());
    int mx1 = -1, mx2 = -1;
    for (int j = nnnn - 1; j >= 0; j--) {
      if (!binary_search(qq.begin(), qq.end(), mx[j].second)) {
        if (mx1 == -1) {
          mx1 = j;
        } else if (mx2 == -1) {
          mx2 = j;
          break;
        }
      } else {
      }
    }
    if (mx1 == -1 && mx2 == -1) {
      printf("0 0\n");
    } else if (mx2 == -1) {
      printf("%d %d\n", mx[mx1].second, ss[mx[mx1].second][0]);
    } else {
      auto it =
          upper_bound(ss[mx[mx1].second].begin(), ss[mx[mx1].second].end(),
                      (ss[mx[mx2].second].back()));
      printf("%d %d\n", mx[mx1].second, *it);
    }
  }
  return 0;
}
