#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 2e5 + 100;
int mx[N];
vector<int> bids[N];
map<int, int> mp;
int l[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    bids[x].push_back(y);
    mx[x] = y;
  }
  for (int i = 1; i <= n; ++i) {
    if (mx[i] != 0) mp[mx[i]] = i;
  }
  mp[0] = 0;
  int q;
  cin >> q;
  while (q--) {
    int k;
    scanf("%d", &k);
    for (int i = 1; i <= k; ++i) {
      scanf("%d", &l[i]);
      if (mx[l[i]]) mp.erase(mx[l[i]]);
    }
    auto it = mp.end();
    it--;
    int ansi = it->second;
    if (it == mp.begin()) {
      printf("0 0\n");
    } else {
      it--;
      printf("%d %d\n", ansi,
             (*lower_bound(bids[ansi].begin(), bids[ansi].end(), it->first)));
    }
    for (int i = 1; i <= k; ++i)
      if (mx[l[i]]) mp[mx[l[i]]] = l[i];
  }
  return 0;
}
