#include <bits/stdc++.h>
int t[200001];
std::vector<int> p[200001];
int main() {
  int n, a, b, q, k, l;
  std::bitset<200001> f;
  auto c = [](int l, int r) { return p[l].back() > p[r].back(); };
  std::scanf("%d", &n);
  ++n;
  for (int i(0); i < n; ++i) {
    t[i] = i;
    p[i].push_back(0);
  }
  for (int i(1); i < n; ++i) {
    std::scanf("%d%d", &a, &b);
    p[a - 1].push_back(b);
  }
  std::stable_sort(t, t + n, c);
  std::scanf("%d", &q);
  while (0 < q--) {
    f.reset();
    std::scanf("%d", &k);
    while (0 < k--) {
      std::scanf("%d", &l);
      f.set(l - 1);
    }
    a = b = -1;
    for (int i(0); i < n; ++i) {
      if (f[t[i]]) continue;
      if (a < 0) {
        a = t[i];
      } else {
        b = t[i];
        break;
      }
    }
    if (p[a].back() == 0) {
      std::puts("0 0");
    } else {
      auto it = std::upper_bound(p[a].begin(), p[a].end(), p[b].back());
      std::printf("%d %d\n", a + 1, *it);
    }
  }
  return 0;
}
