#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
struct Node {
  int id, p;
  bool operator<(const Node& b) const { return p < b.p; }
};
vector<int> v[MAXN];
set<Node> s;
int n, m, t;
int mx[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    if (v[i].size()) s.insert(Node{i, v[i][v[i].size() - 1]});
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &mx[i]);
      if (v[mx[i]].size()) s.erase(Node{mx[i], v[mx[i]][v[mx[i]].size() - 1]});
    }
    set<Node>::iterator it;
    if (s.size() == 0) {
      puts("0 0");
    } else if (s.size() == 1) {
      it = s.begin();
      printf("%d %d\n", it->id, v[it->id][0]);
    } else {
      it = s.end();
      it--;
      int a, b;
      a = it->id;
      it--;
      b = it->p;
      vector<int>::iterator ite;
      ite = lower_bound(v[a].begin(), v[a].end(), b);
      printf("%d %d\n", a, *ite);
    }
    for (int i = 1; i <= m; i++) {
      if (v[mx[i]].size()) s.insert(Node{mx[i], v[mx[i]][v[mx[i]].size() - 1]});
    }
  }
}
