#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, q, k, ans1, ans2;
int mxv[N], l[N];
map<int, int> id;
map<int, int>::iterator it;
vector<int> v[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    mxv[a] = b;
    v[a].push_back(b);
  }
  id[0] = 0;
  for (int i = 1; i <= n; i++)
    if (mxv[i]) id[mxv[i]] = i;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
      scanf("%d", &l[i]);
      if (mxv[l[i]]) id.erase(mxv[l[i]]);
    }
    it = id.end();
    it--;
    if (it == id.begin())
      ans1 = ans2 = 0;
    else {
      ans1 = it->second;
      it--;
      ans2 = *lower_bound(v[ans1].begin(), v[ans1].end(), it->first);
    }
    printf("%d %d\n", ans1, ans2);
    for (int i = 1; i <= k; i++) {
      if (mxv[l[i]]) id[mxv[l[i]]] = l[i];
    }
  }
  return 0;
}
