#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 7;
int n, k;
vector<int> v[MAX];
vector<int> del_list;
int mx[MAX];
set<int> maxi_list;
map<int, int> M;
void gen() {
  for (int i = 1; i <= n; i++) mx[i] = v[i].size() == 0 ? INT_MIN : v[i].back();
  for (int i = 1; i <= n; i++)
    if (mx[i] != INT_MIN) maxi_list.insert(mx[i]), M[mx[i]] = i;
}
void revert(vector<int>& temp) {
  for (auto j : temp) maxi_list.insert(j);
}
pair<int, int> func() {
  pair<int, int> ans = make_pair(0, 0);
  vector<int> temp;
  for (auto j : del_list)
    if (mx[j] != INT_MIN) maxi_list.erase(mx[j]), temp.push_back(mx[j]);
  if (maxi_list.size() == 0)
    revert(temp);
  else if (maxi_list.size() == 1) {
    auto j = maxi_list.end();
    j--;
    int ind = M[*j];
    ans = make_pair(ind, v[ind][0]);
    revert(temp);
  } else {
    auto j = maxi_list.end();
    j--;
    int ind = M[*j];
    j--;
    int req = *j;
    int val = *upper_bound(v[ind].begin(), v[ind].end(), req);
    ans = make_pair(ind, val);
    revert(temp);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
  }
  gen();
  int q;
  scanf("%d", &q);
  while (q--) {
    del_list.clear();
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
      int x;
      scanf("%d", &x);
      del_list.push_back(x);
    }
    pair<int, int> ans = func();
    printf("%d %d\n", ans.first, ans.second);
  }
  return 0;
}
