#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)LLONG_MAX;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int dx8[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int dy8[9] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
long long ipow(long long base, long long exp) {
  long long result = 1;
  while (exp) {
    if (exp & 1) result = (result * base);
    exp >>= 1;
    base = (base * base);
  }
  return result;
}
string tos(long long n) {
  stringstream ss;
  string ans;
  ss << n;
  ss >> ans;
  return ans;
}
long long toll(string n) { return atoll(n.c_str()); }
long long dist(long long x1, long long y1, long long x2, long long y2) {
  return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2));
}
int doubleCompare(double x, double y) {
  if (fabs(x - y) <= 1e-100) return 0;
  if (x < y) return -1;
  return 1;
}
long long mod(long long x, long long m) { return (x % m + m) % m; }
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
const int N = 1000011;
int arr[N];
vector<vector<int> > v(N);
set<int> data;
map<int, int> mpp;
int main() {
  int n, x, y, q;
  cin >> n;
  while (n--) {
    cin >> x >> y;
    v[x].push_back(y);
    mpp[y] = x;
  }
  for (int i = 0; i < N; i++) {
    if (v[i].size() != 0) {
      data.insert(v[i][v[i].size() - 1]);
    }
  }
  cin >> q;
  while (q--) {
    int nn;
    cin >> nn;
    for (int i = 0; i < nn; i++) {
      cin >> x;
      arr[i] = x;
      if (v[x].size() != 0) {
        data.erase(v[x][v[x].size() - 1]);
      }
    }
    if (data.size() == 0)
      cout << "0 0\n";
    else if (data.size() == 1) {
      int onwer = mpp[*(data.begin())];
      cout << onwer << " " << v[onwer][0] << "\n";
    } else {
      int maxV = *(data.rbegin());
      int owner = mpp[*(data.rbegin())];
      data.erase(*(data.rbegin()));
      int secMax = *(data.rbegin());
      int val = upper_bound(v[owner].begin(), v[owner].end(), secMax) -
                v[owner].begin();
      cout << owner << " " << v[owner][val] << "\n";
      ;
      data.insert(maxV);
    }
    for (int i = 0; i < nn; i++) {
      int x = arr[i];
      if (v[x].size() != 0) {
        data.insert(v[x][v[x].size() - 1]);
      }
    }
  }
}
