#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n;
int a[N];
vector<int> v[N];
set<pair<int, int> > s;
int mx[N];
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x >> a[i];
    x--;
    v[x].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (v[i].size() == 0)
      mx[i] = -1;
    else {
      mx[i] = v[i][v[i].size() - 1];
      s.insert(make_pair(-mx[i], i));
    }
  }
  vector<pair<int, int> > ans;
  int q;
  cin >> q;
  for (int o = 0; o < q; o++) {
    int k;
    vector<int> que;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int x;
      cin >> x;
      x--;
      que.push_back(x);
    }
    for (int i = 0; i < k; i++)
      if (mx[que[i]] != -1) s.erase(make_pair(-mx[que[i]], que[i]));
    if (s.size() == 0) {
      ans.push_back(make_pair(-1, 0));
      for (int i = 0; i < k; i++)
        if (mx[que[i]] != -1) s.insert(make_pair(-mx[que[i]], que[i]));
      continue;
    }
    auto t = *(s.begin());
    s.erase(t);
    if (s.size() == 0) {
      ans.push_back(make_pair(t.second, a[v[t.second][0]]));
      s.insert(t);
      for (int i = 0; i < k; i++)
        if (mx[que[i]] != -1) s.insert(make_pair(-mx[que[i]], que[i]));
      continue;
    }
    auto u = *(s.begin());
    int j = upper_bound(v[t.second].begin(), v[t.second].end(), mx[u.second]) -
            v[t.second].begin();
    ans.push_back(make_pair(t.second, a[v[t.second][j]]));
    s.insert(u);
    s.insert(t);
    for (int i = 0; i < k; i++)
      if (mx[que[i]] != -1) s.insert(make_pair(-mx[que[i]], que[i]));
  }
  for (int i = 0; i < q; i++)
    cout << ans[i].first + 1 << " " << ans[i].second << endl;
  return 0;
}
