#include <bits/stdc++.h>
using namespace std;
struct Bet {
  int id;
  int amount;
  int time;
  Bet() {}
  Bet(int a, int b, int c) {
    id = a;
    time = b;
    amount = c;
  }
  bool operator<(const struct Bet &rhs) const { return time < rhs.time; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<Bet> v;
  vector<vector<Bet> > bets(n);
  for (int i = 0; i < n; ++i) {
    int a;
    int b;
    cin >> a >> b;
    a--;
    v.push_back(Bet(a, i, b));
    bets[a].push_back(Bet(a, i, b));
  }
  vector<bool> have(n, false);
  vector<Bet> temp;
  for (int i = n - 1; i >= 0; --i) {
    if (!have[v[i].id]) {
      temp.push_back(v[i]);
      have[v[i].id] = true;
    }
  }
  stack<Bet> lastbet;
  for (int i = temp.size() - 1; i >= 0; --i) {
    lastbet.push(temp[i]);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    vector<bool> remove(n, false);
    for (int j = 0; j < k; ++j) {
      int a;
      cin >> a;
      a--;
      remove[a] = true;
    }
    vector<Bet> save;
    Bet winner = Bet(-1, -1, 0);
    while (!lastbet.empty()) {
      Bet top = lastbet.top();
      if (!remove[top.id]) {
        if (winner.id >= 0) {
          break;
        }
        winner = top;
      }
      save.push_back(top);
      lastbet.pop();
    }
    if (winner.id >= 0) {
      if (!lastbet.empty()) {
        Bet nextTop = lastbet.top();
        int n = bets[winner.id].size();
        for (int pow = 20, shift = 1 << pow; pow >= 0;
             pow--, shift = 1 << pow) {
          int idx = n - shift;
          if (idx >= 0) {
            if (bets[winner.id][idx].time > nextTop.time) {
              n = idx;
            }
          }
        }
        winner = bets[winner.id][n];
      } else {
        winner = bets[winner.id][0];
      }
    }
    cout << winner.id + 1 << ' ' << winner.amount << endl;
    for (int j = save.size() - 1; j >= 0; --j) {
      lastbet.push(save[j]);
    }
  }
  return 0;
}
