#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T b) {
  if (a < b) a = b;
}
void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int N = 3e5 + 7;
set<pair<int, int> > all;
int mx[N], n, q;
vector<int> a[N];
int b[N];
const int inf = 1e9 + 7;
const long long linf = 1e17 + 7;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int p, q;
    scanf("%d%d", &p, &q);
    a[p].push_back(q);
    mx[p] = q;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i].empty()) continue;
    all.insert(make_pair(mx[i], i));
  }
  scanf("%d", &q);
  while (q--) {
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; ++i) {
      scanf("%d", b + i);
      if (a[b[i]].empty()) continue;
      all.erase(make_pair(mx[b[i]], b[i]));
    }
    if (all.empty()) {
      puts("0 0");
    } else {
      int win = (all.rbegin())->second;
      all.erase(make_pair(mx[win], win));
      if (all.empty()) {
        printf("%d %d\n", win, a[win][0]);
      } else {
        int ul = -1, ur = a[win].size() - 1, maxd = (all.rbegin())->first;
        while (ur - ul > 1) {
          int mid = ul + ur >> 1;
          if (a[win][mid] > maxd)
            ur = mid;
          else
            ul = mid;
        }
        printf("%d %d\n", win, a[win][ur]);
      }
      all.insert(make_pair(mx[win], win));
    }
    for (int i = 0; i < k; ++i) {
      if (a[b[i]].empty()) continue;
      all.insert(make_pair(mx[b[i]], b[i]));
    }
  }
  return 0;
}
