#include <bits/stdc++.h>
using namespace std;
const int N = 200022;
vector<vector<int> > v(N);
vector<int> ovr(N);
vector<pair<int, int> > singles;
vector<int> flashed;
void solve() {
  int left = -1;
  for (int i = singles.size() - 1; i >= 0; i--) {
    if (binary_search((flashed).begin(), (flashed).end(), singles[i].second)) {
    } else {
      left = singles[i].second;
      break;
    }
  }
  if (left == -1) {
    cout << "0 0\n";
    return;
  }
  int l = 0;
  int r = v[left].size() - 1;
  int ans;
  while (l <= r) {
    int mid = l + r;
    mid /= 2;
    int tot = v[left].size() - mid;
    for (auto it : flashed) {
      auto itt = upper_bound((v[it]).begin(), (v[it]).end(), v[left][mid]);
      tot += v[it].end() - itt;
    }
    auto ittt = lower_bound((ovr).begin(), (ovr).end(), v[left][mid]);
    if (tot == ovr.end() - ittt) {
      ans = v[left][mid];
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << left << " " << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    ovr.push_back(b);
    v[a].push_back(b);
  }
  for (int i = 0; i < N; i++)
    if (v[i].size()) {
      singles.push_back({v[i].back(), i});
    }
  sort((singles).begin(), (singles).end());
  int q;
  cin >> q;
  while (q--) {
    flashed.clear();
    int l;
    cin >> l;
    while (l--) {
      cin >> a;
      flashed.push_back(a);
    }
    sort((flashed).begin(), (flashed).end());
    solve();
  }
  return 0;
}
