#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, q;
int person[N], bid[N], order[N], who[N];
vector<int> pos[N];
set<int> SET;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &person[i], &bid[i]);
    pos[person[i]].push_back(i);
  }
  int cntr = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (order[person[i]] == 0) {
      order[person[i]] = ++cntr;
      who[cntr] = person[i];
      SET.insert(cntr);
    }
  }
  scanf("%d", &q);
  int k, x;
  while (q--) {
    scanf("%d", &k);
    vector<int> tmp;
    for (int i = 0; i < k; i++) {
      scanf("%d", &x);
      tmp.push_back(x);
      int dd = order[x];
      if (dd != 0) SET.erase(dd);
    }
    if ((int)(SET).size() == 0) {
      printf("0 0\n");
    } else if ((int)(SET).size() == 1) {
      int prsn = who[*SET.begin()];
      printf("%d %d\n", prsn, bid[pos[prsn][0]]);
    } else {
      int prsn1 = -1, prsn2 = -1;
      for (auto it = SET.begin(); it != SET.end(); it++) {
        if (prsn1 == -1) {
          prsn1 = who[*it];
        } else if (prsn2 == -1) {
          prsn2 = who[*it];
        } else {
          break;
        }
      }
      int last = pos[prsn2].back();
      int idx = lower_bound((pos[prsn1]).begin(), (pos[prsn1]).end(), last) -
                pos[prsn1].begin();
      printf("%d %d\n", prsn1, bid[pos[prsn1][idx]]);
    }
    for (int i = 0; i < k; i++) {
      int dd = order[tmp[i]];
      if (dd != 0) SET.insert(dd);
    }
  }
  return 0;
}
