#include <bits/stdc++.h>
using namespace std;
long long p = 2;
long long mod = 1000000007;
long long deg[200000];
int n;
vector<pair<int, int> > best;
vector<int> mx;
vector<int> part;
vector<vector<pair<int, int> > > bets;
vector<long long> hsh;
set<int> l;
bool check(int bet, int idx, int winner) {
  long long expected_hash = deg[winner];
  for (int i : l) {
    if (mx[i] > bet) expected_hash = (expected_hash + deg[i]) % mod;
  }
  return expected_hash == hsh[idx];
}
int main() {
  ios_base::sync_with_stdio(false);
  deg[0] = 1;
  for (int i = 1; i < 200000; i++) deg[i] = (deg[i - 1] * p) % mod;
  cin >> n;
  mx.resize(n, 0);
  for (int i = 0; i < n; i++) best.push_back(make_pair(0, i));
  bets.resize(n);
  for (int a, b, i = 0; i < n; i++) {
    cin >> a >> b;
    a--;
    part.push_back(a);
    if (b > best[a].first) best[a].first = b;
    mx[a] = b;
    bets[a].push_back(make_pair(b, i));
  }
  sort(best.begin(), best.end());
  vector<bool> used;
  used.resize(n, false);
  hsh.resize(n);
  hsh[n - 1] = deg[part[n - 1]];
  used[part[n - 1]] = true;
  for (int i = n - 2; i >= 0; i--)
    if (used[part[i]])
      hsh[i] = hsh[i + 1];
    else {
      hsh[i] = (hsh[i + 1] + deg[part[i]]) % mod;
      used[part[i]] = true;
    }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    l.clear();
    for (int t, i = 0; i < k; i++) {
      cin >> t;
      t--;
      l.insert(t);
    }
    int winner = -1;
    for (int i = n - 1; i >= 0; i--)
      if (best[i].first == 0)
        break;
      else if (!l.count(best[i].second)) {
        winner = best[i].second;
        break;
      }
    if (winner == -1)
      cout << 0 << " " << 0 << endl;
    else {
      int l = 0, r = bets[winner].size() - 1;
      int ans = 0;
      while (l <= r) {
        int x = (l + r) / 2;
        if (check(bets[winner][x].first, bets[winner][x].second, winner)) {
          r = x - 1;
          ans = bets[winner][x].first;
        } else
          l = x + 1;
      }
      cout << winner + 1 << " " << ans << endl;
    }
  }
  return 0;
}
