#include <bits/stdc++.h>
using namespace std;
const int N = (int)250000, md = 1e7, limit = 1e8;
const long double eps = 1e-9, eps1 = 1e-20, PI = 3.14159265358979323846,
                  OOO = 1e100L, lim = sqrt(1e9 + 100);
const long long OO = 1e18 * 8, mod = 1e9 + 7;
int mx[N], t[N];
set<pair<int, int>> st;
set<int> ls[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int n, a, b, q, k;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a >> b, mx[a] = b, ls[a].insert(b);
  for (int i = 0; i <= n; i++)
    if (mx[i]) st.insert(make_pair(mx[i], i));
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> k;
    for (int i = 0; i < k; i++)
      cin >> t[i], st.erase(make_pair(mx[t[i]], t[i]));
    if (st.empty())
      cout << "0 0\n";
    else {
      set<pair<int, int>>::iterator i = --st.end();
      set<pair<int, int>>::iterator j;
      set<int>::iterator ans;
      if (st.size() > 1) {
        j = --i;
        i++;
      }
      cout << i->second << ' ';
      if (st.size() == 1)
        ans = ls[i->second].begin();
      else
        ans = ls[i->second].upper_bound(*(--(ls[j->second].end())));
      cout << *ans << '\n';
    }
    for (int i = 0; i < k; i++)
      if (mx[t[i]]) st.insert(make_pair(mx[t[i]], t[i]));
  }
  return 0;
}
