#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int pmax[N], pmin[N], e[N];
vector<int> P[N];
int main()
{
    memset(pmin, 0x3f3f3f3f, sizeof(pmin));
    int n, q, k;
    scanf("%d", &n);
    for (int i = 0, p, x; i < n; i++)
        scanf("%d%d", &p, &x),
            P[p].push_back(x),
            pmax[p] = max(pmax[p], x),
            pmin[p] = min(pmin[p], x);
    set<pair<int, int>> s;
    for (int i = 1; i <= n; i++)
        if (P[i].size())
            s.insert(make_pair(pmax[i], i));
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d", &k);
        for (int i = 0; i < k; i++)
            scanf("%d", e + i);
        for (int i = 0; i < k; i++)
            s.erase(make_pair(pmax[e[i]], e[i]));
        if (s.empty())
            puts("0 0");
        else if (s.size() == 1)
            printf("%d %d\n", s.begin()->second, pmin[s.begin()->second]);
        else
        {
            auto ite = s.rbegin();
            auto p1 = *(ite++), p2 = *(ite++);
            printf("%d %d\n", p1.second, *upper_bound(P[p1.second].begin(), P[p1.second].end(), p2.first));
        }
        for (int i = 0; i < k; i++)
            if (P[e[i]].size())
                s.insert(make_pair(pmax[e[i]], e[i]));
    }
    return 0;
}