#include <bits/stdc++.h>
using namespace std;
long long int n, q, k, a1, b, i, j;
long long int mx[212345], a[212345];
set<pair<long long int, long long int> > s;
vector<long long int> v[212345];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a1 >> b;
    a1--;
    v[a1].push_back(b);
    if (b > mx[a1]) {
      mx[a1] = b;
    }
  }
  for (i = 0; i < n; i++) {
    if (mx[i] > 0) s.insert(make_pair(mx[i], i));
  }
  cin >> q;
  while (q--) {
    cin >> k;
    for (i = 0; i < k; i++) {
      long long int u;
      cin >> u;
      a[i] = u - 1;
      if (mx[a[i]] > 0) s.erase(make_pair(mx[a[i]], a[i]));
    }
    if (s.empty()) {
      cout << "0 0\n";
    } else if (s.size() == 1) {
      auto it = s.begin();
      long long int val = it->second;
      cout << val + 1 << " " << v[val][0];
      cout << "\n";
    } else {
      auto it = s.end();
      it--;
      auto it2 = it;
      it2--;
      auto it3 = upper_bound(v[it->second].begin(), v[it->second].end(),
                             mx[it2->second]);
      cout << it->second + 1 << " " << *(it3);
      cout << "\n";
      ;
    }
    for (i = 0; i < k; i++) {
      if (mx[a[i]] > 0) {
        s.insert(make_pair(mx[a[i]], a[i]));
      }
    }
  }
  return 0;
}
