#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
vector<int> vec[MAX];
bool vis[MAX];
int absent[MAX];
int main() {
  int n, a, b, q, k;
  while (scanf("%d", &n) != EOF) {
    memset(vis, false, sizeof(vis));
    for (int i = 1; i <= n; i++) {
      vec[i].clear();
    }
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &a, &b);
      vec[a].push_back(b);
    }
    vector<pair<int, int> > v;
    for (int i = 1; i <= n; i++) {
      if (vec[i].size() > 0) {
        v.push_back(pair<int, int>(vec[i][vec[i].size() - 1], i));
      }
    }
    sort(v.begin(), v.end(), greater<pair<int, int> >());
    scanf("%d", &q);
    while (q--) {
      scanf("%d", &k);
      for (int i = 0; i < k; i++) {
        scanf("%d", &absent[i]);
        vis[absent[i]] = true;
      }
      int t1 = -1, t2 = -1;
      for (int i = 0; i < v.size(); i++) {
        if (t1 != -1 && t2 != -1) {
          break;
        }
        if (vis[v[i].second]) {
          continue;
        }
        if (t1 == -1) {
          t1 = v[i].second;
        } else {
          t2 = v[i].second;
        }
      }
      if (t1 == -1 && t2 == -1) {
        puts("0 0");
      } else if (t2 == -1) {
        printf("%d %d\n", t1, vec[t1][0]);
      } else {
        int ans = vec[t1][lower_bound(vec[t1].begin(), vec[t1].end(),
                                      vec[t2][vec[t2].size() - 1]) -
                          vec[t1].begin()];
        printf("%d %d\n", t1, ans);
      }
      for (int i = 0; i < k; i++) {
        vis[absent[i]] = false;
      }
    }
  }
  return 0;
}
