#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long double PI = 3.1415926535897932384626433832795;
const int N = 200100;
vector<int> b[N];
set<pair<int, int> > mx;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    b[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (!b[i].empty()) {
      mx.insert(make_pair(b[i].back(), i));
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    vector<int> v;
    for (int i = 0; i < k; i++) {
      int l;
      cin >> l;
      if (!b[l].empty()) {
        v.push_back(l);
        mx.erase(make_pair(b[l].back(), l));
      }
    }
    if (mx.empty()) {
      cout << "0 0" << endl;
    } else if (mx.size() == 1) {
      int it = mx.begin()->second;
      cout << it << ' ' << b[it][0] << endl;
    } else {
      auto it = mx.rbegin();
      auto jt = it;
      jt++;
      auto kt =
          upper_bound(b[it->second].begin(), b[it->second].end(), jt->first);
      cout << it->second << ' ' << *kt << endl;
    }
    for (auto& i : v) {
      mx.insert(make_pair(b[i].back(), i));
    }
  }
  return 0;
}
