#include <bits/stdc++.h>
inline int rit() {
  int f = 0, key = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') key = -1;
    ;
  } while (ch < '0' || ch > '9');
  do {
    f = f * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * key;
}
using namespace std;
int n, Q, k, a, b;
set<pair<int, int>, greater<pair<int, int> > > pos;
vector<int> vct[200000 + 5];
int del[200000 + 5];
int main(void) {
  n = rit();
  for (int i = 0; i < int(n); i++) {
    a = rit(), b = rit();
    vct[a].push_back(b);
  }
  for (int i = 1; i <= int(n); i++) {
    if (!vct[i].empty()) {
      pos.insert({vct[i].back(), i});
    }
  }
  Q = rit();
  while (Q--) {
    k = rit();
    for (int i = 0; i < int(k); i++) {
      del[i] = rit();
      if (!vct[del[i]].empty()) pos.erase({vct[del[i]].back(), del[i]});
    }
    if (pos.empty()) {
      printf("0 0\n");
    } else if (pos.size() == 1) {
      auto it = pos.begin();
      printf("%d %d\n", (*it).second, vct[(*it).second].front());
    } else {
      auto it = pos.begin();
      int pl = (*it).second;
      ++it;
      printf("%d %d\n", pl,
             *lower_bound(vct[pl].begin(), vct[pl].end(), (*it).first));
    }
    for (int i = 0; i < int(k); i++) {
      if (!vct[del[i]].empty()) pos.insert({vct[del[i]].back(), del[i]});
    }
  }
}
