#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const int MOD = 1e9 + 7;
const int oo = MOD;
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
const int mx = 2e5 + 5;
vector<int> cst[mx], idx;
int n, val[mx];
bool out[mx];
bool hts(int x, int y) { return val[x] > val[y]; }
int main() {
  int a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    cst[a].push_back(b);
    val[a] = b;
    if (!out[a]) idx.push_back(a), out[a] = 1;
  }
  memset(out, 0, sizeof out);
  sort(idx.begin(), idx.end(), hts);
  int q, k;
  cin >> q;
  n = (int)idx.size();
  vector<int> x;
  while (q-- && scanf("%d", &k)) {
    x.resize(k);
    for (int i = 0; i < k; i++) {
      scanf("%d", &x[i]);
      out[x[i]] = 1;
    }
    int u, l;
    u = l = 0;
    for (int i = 0; i < n; i++)
      if (!out[idx[i]]) {
        if (l) {
          u = idx[i];
          break;
        } else
          l = idx[i];
      }
    if (!l)
      puts("0 0");
    else if (!u)
      printf("%d %d\n", l, cst[l][0]);
    else
      printf("%d %d\n", l,
             cst[l][lower_bound(cst[l].begin(), cst[l].end(), val[u]) -
                    cst[l].begin()]);
    for (int i = 0; i < k; i++) out[x[i]] = 0;
  }
  return 0;
}
