#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[200010];
int mark[200010];
vector<pair<int, int> > sorted;
int Query[200010];
int main() {
  int n, q, i, j;
  memset(mark, 0, sizeof(mark));
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    v[x].push_back(make_pair(y, i));
  }
  for (i = 1; i <= n; i++) {
    if ((int)v[i].size() == 0) continue;
    sorted.push_back(make_pair(v[i][v[i].size() - 1].first, i));
  }
  sort(sorted.begin(), sorted.end());
  scanf("%d", &q);
  while (q--) {
    int k, x;
    scanf("%d", &k);
    for (i = 0; i < k; i++) {
      scanf("%d", &Query[i]);
      mark[Query[i]] = 1;
    }
    for (i = (int)sorted.size() - 1; i >= 0; --i)
      if (!mark[sorted[i].second]) break;
    if (i < 0) {
      printf("0 0\n");
      for (i = 0; i < k; i++) mark[Query[i]] = 0;
      continue;
    }
    int p = sorted[i].second;
    int lo = 0, hi = v[p].size() - 1, mid;
    while (lo < hi) {
      mid = (lo + hi) / 2;
      int pos = v[p][mid].second, val = v[p][mid].first;
      int cnt = (int)v[p].size() - 1 - mid;
      for (i = 0; i < k; i++) {
        if ((int)v[Query[i]].size() == 0) continue;
        int pos = upper_bound(v[Query[i]].begin(), v[Query[i]].end(),
                              make_pair(val, 0)) -
                  v[Query[i]].begin();
        cnt += (int)v[Query[i]].size() - pos;
      }
      if (cnt == n - 1 - pos)
        hi = mid;
      else
        lo = mid + 1;
    }
    printf("%d %d\n", p, v[p][lo].first);
    for (i = 0; i < k; i++) mark[Query[i]] = 0;
  }
}
