#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  unordered_map<int, vector<int>> manToBidSet;
  vector<pair<int, int>> maxBidToMan;
  manToBidSet.reserve(n / 2);
  maxBidToMan.reserve(n);
  for (int i = 0; i < n; ++i) {
    int man, bid;
    cin >> man >> bid;
    manToBidSet[man].push_back(bid);
  }
  for (auto it = manToBidSet.begin(), end = manToBidSet.end(); it != end;
       ++it) {
    maxBidToMan.emplace_back(*it->second.rbegin(), it->first);
  }
  sort((maxBidToMan).begin(), (maxBidToMan).end());
  reverse((maxBidToMan).begin(), (maxBidToMan).end());
  int queryCnt;
  cin >> queryCnt;
  for (int q = 0; q < queryCnt; ++q) {
    int k;
    cin >> k;
    vector<int> queries(k);
    for (int i = 0; i < k; ++i) {
      cin >> queries[i];
    }
    sort((queries).begin(), (queries).end());
    int manMaxFirst = -1;
    int manMaxSecond = -1;
    for (auto it = maxBidToMan.begin(), end = maxBidToMan.end(); it != end;
         ++it) {
      int man = it->second;
      if (!binary_search((queries).begin(), (queries).end(), man)) {
        if (manMaxFirst == -1) {
          manMaxFirst = man;
        } else if (manMaxSecond == -1) {
          manMaxSecond = man;
        } else {
          break;
        }
      }
    }
    if (manMaxFirst == -1 && manMaxSecond == -1) {
      cout << "0 0\n";
    } else if (manMaxSecond == -1) {
      int minBid = manToBidSet[manMaxFirst].front();
      cout << manMaxFirst << " " << minBid << "\n";
    } else {
      int maxBid2 = manToBidSet[manMaxSecond].back();
      const auto& v = manToBidSet[manMaxFirst];
      int optimalBid1 = *upper_bound((v).begin(), (v).end(), maxBid2);
      cout << manMaxFirst << " " << optimalBid1 << "\n";
    }
  }
  return 0;
}
