#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getrnd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e7, CINF = 1e9 + 7, N = 2e5 + 3;
int tree[4 * N];
void build(int v, int tl, int tr, vector<int>& a) {
  if (tl == tr)
    tree[v] = a[tl];
  else {
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm, a);
    build(2 * v + 1, tm + 1, tr, a);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  }
}
void update(int v, int tl, int tr, int pos, int x) {
  if (tl == tr)
    tree[v] += x;
  else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(2 * v, tl, tm, pos, x);
    else
      update(2 * v + 1, tm + 1, tr, pos, x);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  if (l > r) return -INF;
  if (tl == l && tr == r)
    return tree[v];
  else {
    int tm = (tl + tr) / 2;
    return max(get(2 * v, tl, tm, l, min(r, tm)),
               get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
  }
}
void solve() {
  int n;
  cin >> n;
  vector<int> mn(n, CINF), lst(n, -INF);
  vector<vector<int>> pos(n);
  vector<pair<int, int>> arr;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    arr.emplace_back(a, b);
    relax(mn[a], b);
    lst[a] = i;
    pos[a].emplace_back(i);
  }
  int q;
  cin >> q;
  build(1, 0, n - 1, lst);
  while (q--) {
    int k;
    cin >> k;
    vector<int> qs(k);
    for (int j = 0; j < k; ++j) {
      cin >> qs[j];
      --qs[j];
      update(1, 0, n - 1, qs[j], -2 * INF);
    }
    int ind = get(1, 0, n - 1, 0, n - 1);
    if (ind <= -INF) {
      cout << "0 0\n";
    } else {
      int a = arr[ind].first;
      update(1, 0, n - 1, a, -2 * INF);
      int s = get(1, 0, n - 1, 0, n - 1);
      if (s <= -INF) {
        cout << a + 1 << ' ' << mn[a] << '\n';
      } else {
        cout << a + 1 << ' '
             << arr[(*upper_bound(pos[a].begin(), pos[a].end(), s))].second
             << '\n';
      }
      update(1, 0, n - 1, a, 2 * INF);
    }
    for (int j = 0; j < k; ++j) update(1, 0, n - 1, qs[j], 2 * INF);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  srand(time(0));
  int t = 1;
  while (t--) solve();
  return 0;
}
