#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 200010;
int N;
vector<int> bid[MAX_N];
vector<int> max_bid;
int main() {
  scanf("%d", &N);
  max_bid.resize(N);
  set<pii, greater<pii>> member;
  for (int i = 0; i < N; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    bid[a].push_back(b);
    max_bid[a] = max(max_bid[a], b);
  }
  for (int i = 0; i < N; i++) {
    if (not bid[i].empty()) {
      member.emplace(make_pair(max_bid[i], i));
    }
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int k;
    scanf("%d", &k);
    vector<int> remove_list(k);
    for (int i = 0; i < k; i++) {
      int l;
      scanf("%d", &l);
      l--;
      remove_list[i] = l;
    }
    for (auto &val : remove_list) {
      int bid = max_bid[val];
      member.erase(make_pair(bid, val));
    }
    if (member.empty()) {
      printf("0 0\n");
    } else if (member.size() == 1) {
      pii res = *member.begin();
      cout << res.second + 1 << " " << bid[res.second][0] << endl;
    } else {
      pii res1 = *member.begin();
      pii res2 = *(++member.begin());
      int mx = bid[res2.second].back();
      int t =
          *lower_bound(bid[res1.second].begin(), bid[res1.second].end(), mx);
      cout << res1.second + 1 << " " << t << endl;
    }
    for (auto &val : remove_list) {
      if (not bid[val].empty()) {
        member.emplace(make_pair(max_bid[val], val));
      }
    }
  }
  return 0;
}
