#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
int maxbid[MAX];
vector<int> ve[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  set<pair<int, int>> s;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    ve[a].push_back(b);
    maxbid[a] = b;
  }
  for (int i = 1; i <= n; i++) {
    if (maxbid[i]) s.insert(make_pair(maxbid[i], i));
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int ear[MAX];
    int k;
    cin >> k;
    for (int j = 1; j <= k; j++) {
      cin >> ear[j];
      s.erase(pair<int, int>(maxbid[ear[j]], ear[j]));
    }
    if (s.size() == 0)
      cout << "0 0" << endl;
    else if (s.size() == 1) {
      cout << s.begin()->second << ' ' << *ve[s.begin()->second].begin()
           << endl;
    } else {
      auto it1 = s.end(), it2 = s.end();
      it1--, it2--, it2--;
      cout << it1->second << ' '
           << ve[it1->second][upper_bound(ve[it1->second].begin(),
                                          ve[it1->second].end(), it2->first) -
                              ve[it1->second].begin()]
           << endl;
    }
    for (int j = 1; j <= k; j++) {
      if (maxbid[ear[j]]) s.insert(make_pair(maxbid[ear[j]], ear[j]));
    }
  }
}
