#include <bits/stdc++.h>
using namespace std;
vector<int> a[200001];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a[x].push_back(y);
  }
  set<pair<int, int> > S;
  for (int i = 1; i <= n; i++) {
    sort(a[i].begin(), a[i].end());
    if (!a[i].empty()) {
      S.insert(make_pair(a[i][a[i].size() - 1], i));
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    scanf("%d", &k);
    vector<pair<int, int> > temp;
    for (int i = 1; i <= k; i++) {
      int x;
      scanf("%d", &x);
      if (a[x].size()) {
        S.erase(make_pair(a[x][a[x].size() - 1], x));
        temp.push_back(make_pair(a[x][a[x].size() - 1], x));
      }
    }
    if (S.size() == 0) {
      cout << "0 0\n";
    } else if (S.size() == 1) {
      set<pair<int, int> >::iterator it;
      it = S.begin();
      int x = it->second, y = it->first;
      printf("%d %d\n", x, a[x][0]);
    } else {
      set<pair<int, int> >::reverse_iterator it;
      it = S.rbegin();
      int u = it->second;
      it++;
      int x = it->second, y = it->first;
      int ans = *upper_bound(a[u].begin(), a[u].end(), y);
      printf("%d %d\n", u, ans);
    }
    for (int i = 0; i < temp.size(); i++) {
      S.insert(temp[i]);
    }
  }
  return 0;
}
