#include <bits/stdc++.h>
using namespace std;
vector<int> bid(200000), bidder(200000), max_bid(200000), bids[200001];
struct comp {
  bool operator()(const int &a, const int &b) {
    return max_bid[a] < max_bid[b];
  }
};
set<int, comp> st;
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &bidder[i], &bid[i]);
    bids[bidder[i]].push_back(bid[i]);
    max_bid[bidder[i]] = bid[i];
  }
  for (int i = 1; i <= n; ++i)
    if (max_bid[i] != 0) st.insert(i);
  scanf("%d", &m);
  while (m--) {
    int k;
    scanf("%d", &k);
    vector<int> temp(k);
    for (int i = 0; i < k; ++i) {
      scanf("%d", &temp[i]);
      if (max_bid[temp[i]] != 0) {
        st.erase(temp[i]);
      }
    }
    if (st.size() == 0)
      printf("0 0\n");
    else if (st.size() == 1)
      printf("%d %d\n", *st.begin(), bids[*st.begin()][0]);
    else {
      set<int, comp>::iterator it = --st.end();
      int winner = *it;
      --it;
      int sec = *(it);
      int win_bid =
          *lower_bound(bids[winner].begin(), bids[winner].end(), max_bid[sec]);
      printf("%d %d\n", winner, win_bid);
    }
    for (auto it : temp)
      if (max_bid[it] != 0) {
        st.insert(it);
      }
  }
  return 0;
}
