#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10 + 6;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
const int MAX_N = 1e5 + 5;
const int LG = 25;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int a[MAX_N];
pair<int, int> p[MAX_N];
vector<int> v[MAX_N];
bool check(int ind, int pos, int val) {
  if (pos > v[ind].size() - 1) return true;
  if (pos < 0) return false;
  if (v[ind][pos] > val)
    return true;
  else
    return false;
}
int main() {
  int n;
  scanf("%d", &n);
  set<pair<int, int> > s;
  int maximo = -1;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    maximo = max(a, maximo);
    v[a].push_back(b);
  }
  for (int i = 1; i < maximo + 1; i++) {
    if (v[i].size() != 0) {
      sort(v[i].begin(), v[i].end());
      s.insert({v[i].back(), i});
    }
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int k;
    scanf("%d", &k);
    vector<int> g(k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &g[j]);
      if (v[g[j]].size() != 0) s.erase({v[g[j]].back(), g[j]});
    }
    if (s.size() == 0) {
      printf("0 0\n");
    } else {
      set<pair<int, int> >::iterator it;
      it = s.end();
      it--;
      int val = it->second;
      int cnt = 0;
      int val1 = -1;
      s.insert({-1, -1});
      for (it = s.end(); it != s.begin(); it--) {
        if (cnt == 0) {
          cnt++;
          continue;
        }
        if (it->second != val) {
          val1 = it->second;
          break;
        }
      }
      s.erase({-1, -1});
      if (val1 == -1) {
        printf("%d %d\n", val, v[val].front());
      } else {
        int ini = -1, fin = 1e5;
        while ((fin - ini) > 1) {
          int mid = (ini + fin) / 2;
          if (check(val, mid, v[val1].back()))
            fin = mid;
          else
            ini = mid;
        }
        printf("%d %d\n", val, v[val][fin]);
      }
    }
    for (int j = 0; j < k; j++) {
      if (v[g[j]].size() != 0) s.insert({v[g[j]].back(), g[j]});
    }
  }
}
