#include <bits/stdc++.h>
using namespace std;
struct thePeople {
  int count;
  int Max;
};
bool cmp(thePeople a, thePeople b) { return a.Max > b.Max; }
int main(void) {
  int num;
  int count, money, peopleNum = 0;
  static thePeople People[200010] = {0};
  static bool visit[200010];
  static vector<int> arr[200010];
  scanf("%d", &num);
  for (int i = 0; i < 200010; i++) {
    People[i].count = i;
    People[i].Max = 0;
  }
  arr[0].push_back(0);
  for (int i = 0; i < num; i++) {
    scanf("%d %d", &count, &money);
    arr[count].push_back(money);
    if (People[count].Max == 0) peopleNum++;
    People[count].Max = money;
  }
  sort(People + 1, People + 200010, cmp);
  int queryNum;
  scanf("%d", &queryNum);
  for (int i = 0; i < queryNum; i++) {
    int start = 0, second = 0;
    int lostnum, n;
    memset(visit, true, sizeof(visit));
    scanf("%d", &lostnum);
    for (int i = 0; i < lostnum; i++) {
      scanf("%d", &n);
      visit[n] = false;
    }
    for (int i = 1; i <= peopleNum; i++)
      if (visit[People[i].count]) {
        if (start == 0)
          start = i;
        else
          second = i;
        if (start != 0 && second != 0) break;
      }
    int MM = People[second].Max;
    int ans = *lower_bound(arr[People[start].count].begin(),
                           arr[People[start].count].end() - 1, MM);
    printf("%d %d\n", People[start].count, ans);
  }
}
