#include <bits/stdc++.h>
using namespace std;
vector<int> mylist[200005];
pair<int, int> v[200005], last_appear[200005];
int f[200005], mark[200005], del_elem[200005];
int n, k, q, nr;
inline int binary_search(int index, int value) {
  int left = 0, right = mylist[index].size() - 1;
  int sol = right;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (mylist[index][mid] < value) {
      left = mid + 1;
    } else {
      sol = mylist[index][mid];
      right = mid - 1;
    }
  }
  return v[sol].second;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &v[i].first, &v[i].second);
    mylist[v[i].first].push_back(i);
  }
  for (int i = n; i >= 1; i--) {
    if (!f[v[i].first]) {
      last_appear[++nr] = make_pair(v[i].first, i);
    }
    f[v[i].first] = 1;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &del_elem[j]);
      mark[del_elem[j]] = 1;
    }
    int index = 0;
    for (int j = 1; j <= nr && !index; j++) {
      if (!mark[last_appear[j].first]) {
        index = j;
      }
    }
    if (!index) {
      printf("0 0\n");
    } else {
      int index2;
      for (index2 = index + 1; index2 <= nr; index2++)
        if (!mark[last_appear[index2].first]) break;
      if (index2 == nr + 1) {
        index = last_appear[index].first;
        printf("%d %d\n", index, v[mylist[index][0]].second);
      } else {
        printf("%d %d\n", last_appear[index].first,
               binary_search(last_appear[index].first,
                             last_appear[index2].second));
      }
    }
    for (int j = 1; j <= k; j++) mark[del_elem[j]] = 0;
  }
  return 0;
}
