#include <bits/stdc++.h>
using namespace std;
struct Bidder {
  long num;
  long maxBid;
  Bidder(long num, long maxBid) : num(num), maxBid(maxBid) {}
  bool operator<(const Bidder& b) const { return maxBid < b.maxBid; }
};
struct BidList {
  vector<long>* bids;
  BidList(vector<long>* bids) : bids(bids) {}
  BidList() {}
};
long BinarySearch(long bid_to_beat, const vector<long>& bidmap) {
  long lo = 0, mid, hi = bidmap.size() - 1, result = -1;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (bidmap[mid] > bid_to_beat) {
      result = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  return bidmap[result];
}
int main() {
  ios_base::sync_with_stdio(false);
  long n;
  cin >> n;
  long a[n], b[n];
  long maxBid[n + 1];
  for (long i = 0; i <= n; ++i) maxBid[i] = -1;
  unordered_map<long, vector<long>> bidmap;
  for (long i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    bidmap[a[i]].push_back(b[i]);
    maxBid[a[i]] = max(maxBid[a[i]], b[i]);
  }
  map<Bidder, BidList> bidders;
  for (long i = 0; i < n; ++i) {
    if (maxBid[a[i]] != -1)
      bidders[Bidder(a[i], maxBid[a[i]])] = BidList(&(bidmap[a[i]]));
  }
  long q;
  cin >> q;
  for (long i = 0; i < q; ++i) {
    long nexc;
    cin >> nexc;
    long exc[nexc];
    for (long j = 0; j < nexc; ++j) {
      long id;
      cin >> id;
      exc[j] = id;
      if (bidders.count(Bidder(id, maxBid[id])) > 0)
        bidders.erase(Bidder(id, maxBid[id]));
    }
    if (bidders.size() == 0) cout << "0 0" << endl;
    if (bidders.size() == 1) {
      cout << bidders.begin()->first.num << " "
           << bidders.begin()->second.bids->at(0) << endl;
    }
    if (bidders.size() >= 2) {
      auto it = bidders.rbegin();
      cout << it->first.num << " ";
      it++;
      long bid_to_beat = it->first.maxBid;
      vector<long>* bidmap = bidders.rbegin()->second.bids;
      cout << BinarySearch(bid_to_beat, *bidmap) << endl;
    }
    for (long j = 0; j < nexc; ++j) {
      auto it = bidders.begin();
      if (maxBid[exc[j]] != -1) {
        bidders[Bidder(exc[j], maxBid[exc[j]])] = BidList(&(bidmap[exc[j]]));
      }
    }
  }
}
