#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
queue<int> qu;
struct Mans {
  int no, val;
} p[200005];
bool cmp(Mans x1, Mans x2) { return x1.val > x2.val; }
bool life[200005];
int ask(int no, int val) {
  int mid, l = 0, r = v[no].size() - 1;
  while (l < r) {
    mid = (l + r) / 2;
    if (v[no][mid] > val)
      r = mid;
    else
      l = mid + 1;
  }
  return v[no][l];
}
int main() {
  int n, q, k;
  int ans1, gg, now, a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    p[i].no = i;
    scanf("%d%d", &a, &b);
    p[a].val = b;
    v[a].push_back(b);
  }
  p[n + 1].val = 0;
  sort(p + 1, p + 1 + n, cmp);
  cin >> q;
  while (q--) {
    ans1 = 0;
    now = 1;
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
      scanf("%d", &gg);
      life[gg] = 1;
      qu.push(gg);
    }
    while (!ans1 || life[p[now].no]) {
      if (!life[p[now].no]) ans1 = now;
      now++;
    }
    if (!p[ans1].val)
      printf("0 0\n");
    else
      printf("%d %d\n", p[ans1].no, ask(p[ans1].no, p[now].val));
    while (!qu.empty()) {
      life[qu.front()] = 0;
      qu.pop();
    }
  }
  return 0;
}
