#include <bits/stdc++.h>
using namespace std;
int N, M, Q, K, ansNo, ansBid;
int no[200005], no2[200005], mks[200005], bid[200005], bid2[200005],
    hilang[200005], daftar[200005];
vector<int> orang[200005];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &no[i], &bid[i]);
    orang[no[i]].push_back(bid[i]);
  }
  for (int i = 0; i < N; i++) {
    mks[no[i]] = i;
  }
  int ptr = 0;
  for (int i = 0; i < N; i++) {
    if (mks[no[i]] == i) {
      no2[ptr] = no[i];
      bid2[ptr++] = bid[i];
    }
  }
  M = ptr;
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d", &K);
    for (int j = 0; j < K; j++) {
      scanf("%d", &daftar[j]);
      hilang[daftar[j]] = 1;
    }
    ansNo = ansBid = 0;
    int batas = 0;
    for (int j = M - 1; j >= 0; j--) {
      if (hilang[no2[j]]) continue;
      if (ansNo == 0 && ansBid == 0) {
        ansNo = no2[j];
        ansBid = bid2[j];
      } else {
        batas = bid2[j];
        break;
      }
    }
    if (ansNo != 0)
      ansBid = *lower_bound(orang[ansNo].begin(), orang[ansNo].end(), batas);
    for (int j = 0; j < K; j++) {
      hilang[daftar[j]] = 0;
    }
    printf("%d %d\n", ansNo, ansBid);
  }
  return 0;
}
