#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U>& a) {
  out << "[" << a.first << " " << a.second << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[ ";
  for (auto& it : a) out << it << " ";
  out << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const set<T>& a) {
  out << "[ ";
  for (auto& it : a) out << it << " ";
  out << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const multiset<T>& a) {
  out << "[ ";
  for (auto& it : a) out << it << " ";
  out << "]";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U>& a) {
  for (auto& it : a) out << it.first << " -> " << it.second << " | ";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, const multimap<T, U>& a) {
  for (auto& it : a) out << it.first << " -> " << it.second << " | ";
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long N = 200010;
long long nbids, nq, lastPosArr[N];
vector<long long> bids[N];
set<pair<long long, long long> > lastPosSet;
void Main() {
  cin >> nbids;
  for (long long i = 0; i < nbids; i++) {
    long long person, bid;
    cin >> person >> bid;
    bids[person].push_back(bid);
    lastPosArr[person] = i + 1;
  }
  for (long long i = 1; i <= nbids; i++) {
    if (bids[i].size() > 0) {
      lastPosSet.insert({lastPosArr[i], i});
    }
  }
  cin >> nq;
  for (long long ii = 0; ii < nq; ii++) {
    vector<long long> remove;
    long long numRemove;
    cin >> numRemove;
    for (long long i = 0; i < numRemove; i++) {
      long long x;
      cin >> x;
      if (bids[x].size() > 0) {
        remove.push_back(x);
        lastPosSet.erase({lastPosArr[x], x});
      }
    }
    if (lastPosSet.size() == 0) {
      cout << "0 0\n";
    } else {
      auto it = lastPosSet.end();
      --it;
      long long winner = (*it).second;
      auto ins = *it;
      cout << winner << " ";
      lastPosSet.erase(it);
      if (lastPosSet.size() == 0) {
        cout << bids[winner][0] << "\n";
      } else {
        it = lastPosSet.end();
        --it;
        long long prevBetter = (*it).second;
        long long prevBet = bids[prevBetter].back();
        long long winBet =
            *(lower_bound(bids[winner].begin(), bids[winner].end(), prevBet));
        cout << winBet << "\n";
      }
      lastPosSet.insert(ins);
    }
    for (long long el : remove) {
      lastPosSet.insert({lastPosArr[el], el});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Main();
}
