#include <bits/stdc++.h>
using namespace std;
int N, Q;
pair<int, int> arr[200005];
vector<int> v[200005];
int k;
vector<int> idx;
inline bool check(int m) {
  int cnt = N - m;
  bool flag = false;
  for (int now : idx) {
    int pos = upper_bound(v[now].begin(), v[now].end(), m) - v[now].begin();
    cnt -= ((int)v[now].size() - pos);
    if (now == arr[m].first) flag = true;
  }
  if (!flag) {
    int now = arr[m].first;
    int pos = upper_bound(v[now].begin(), v[now].end(), m) - v[now].begin();
    cnt -= ((int)v[now].size() - pos);
  }
  return cnt == 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> arr[i].first >> arr[i].second;
    v[arr[i].first].emplace_back(i);
  }
  cin >> Q;
  while (Q--) {
    cin >> k;
    for (int i = 0, u; i < k; i++) {
      cin >> u;
      if (v[u].empty()) continue;
      idx.emplace_back(u);
    }
    int l = 0, r = N, m;
    while (true) {
      if (r - l <= 3) {
        for (m = r; m >= l && check(m); m--)
          ;
        m++;
        break;
      }
      m = (l + r) >> 1;
      if (check(m))
        r = m;
      else
        l = m + 1;
    }
    if (m != 0) {
      int now = arr[m].first;
      l = 0, r = lower_bound(v[now].begin(), v[now].end(), m) - v[now].begin();
      while (true) {
        if (r - l <= 3) {
          for (m = r; m >= l && check(v[now][m]); m--)
            ;
          m++;
          break;
        }
        m = (l + r) >> 1;
        if (check(v[now][m]))
          r = m;
        else
          l = m + 1;
      }
      m = v[now][m];
    }
    cout << arr[m].first << " " << arr[m].second << endl;
    idx.clear();
  }
  return 0;
}
