#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> bids[200010];
set<pair<int, int> > maxs;
int bin_search(int idx, int num, int left, int right) {
  if (bids[idx].empty()) return 0;
  if (num == 0) return bids[idx][0];
  int mid = (left + right) / 2;
  mid = bids[idx][mid];
  if (left == right) return mid;
  if (mid > num) {
    return bin_search(idx, num, left, (left + right) / 2);
  } else {
    return bin_search(idx, num, (left + right) / 2 + 1, right);
  }
}
inline pair<int, int> get_max_bid(int idx) {
  if (bids[idx].empty())
    return make_pair(-1, idx);
  else
    return make_pair(bids[idx][bids[idx].size() - 1], idx);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    bids[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    maxs.insert(get_max_bid(i));
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int qn;
    vector<int> removal;
    scanf("%d", &qn);
    for (int j = 0; j < qn; j++) {
      int m;
      scanf("%d", &m);
      removal.push_back(m);
      maxs.erase(get_max_bid(m));
    }
    int maxn1 = 0;
    int max2 = 0;
    if (maxs.empty()) {
      maxn1 = 0;
    } else {
      auto it = maxs.rbegin();
      maxn1 = it->second;
      if (bids[maxn1].empty()) maxn1 = 0;
      if (maxs.size() > 1) {
        it++;
        max2 = it->first;
      }
    }
    cout << maxn1 << ' ';
    if (maxn1 == 0) {
      cout << 0 << endl;
    } else {
      int result = bin_search(maxn1, max2, 0, bids[maxn1].size() - 1);
      cout << result << endl;
    }
    for (int j = 0; j < qn; j++) {
      maxs.insert(get_max_bid(removal[j]));
    }
  }
  return 0;
}
