#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, a[N], b[N], mx[N], id, q, k, t[N], r;
bool del[N];
int mapping[N], mp[N];
vector<vector<int> > val;
int freq[N], diff[N];
int get(int idx) {
  int ret = 0;
  for (int i = 0; i < k; ++i) {
    if (t[i] == -1) continue;
    if (mx[t[i]] >= idx) ++ret;
  }
  return ret;
}
int main() {
  memset(mp, -1, sizeof mp);
  scanf("%d", &n);
  val.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
    if (mp[a[i]] == -1) {
      mp[a[i]] = id;
      mapping[id] = a[i];
      a[i] = id++;
    } else
      a[i] = mp[a[i]];
    val[a[i]].push_back(i);
    mx[a[i]] = i;
  }
  for (int i = n - 1; i >= 0; --i) {
    diff[i] = diff[i + 1];
    if (++freq[a[i]] == 1) ++diff[i];
  }
  vector<pair<int, int> > v;
  for (int i = 0; i < id; ++i) {
    v.push_back(make_pair(mx[i], i));
  }
  sort(v.begin(), v.end());
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    r = id - 1;
    for (int i = 0; i < k; ++i) {
      scanf("%d", &t[i]);
      if (mp[t[i]] == -1) {
        t[i] = -1;
        continue;
      }
      t[i] = mp[t[i]];
      del[t[i]] = true;
      while (r >= 0 && del[v[r].second]) --r;
    }
    for (int i = 0; i < k; ++i)
      if (t[i] != -1) del[t[i]] = false;
    if (r < 0)
      puts("0 0");
    else {
      int ans = r;
      int l = 0, r = (int)val[v[ans].second].size() - 1, mid, idx;
      int res = r;
      while (l <= r) {
        mid = (l + r) / 2;
        idx = val[v[ans].second][mid];
        if (diff[idx] - get(idx) - 1 == 0) {
          r = mid - 1;
          res = idx;
        } else
          l = mid + 1;
      }
      printf("%d %d\n", mapping[v[ans].second], b[res]);
    }
  }
  return 0;
}
