#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> bids(n + 1);
    set<pair<int, int>> active;
    for (int i = 0, id, b; i < n; i++) {
        cin >> id >> b;
        bids[id].push_back(b);
    }
    for (int id = 1; id <= n; id++)
        if (!bids[id].empty())
            active.insert({bids[id].back(), id});
    int q;
    cin >> q;
    while (q--) {
        int k;
        cin >> k;
        vector<pair<int, int>> removed;
        while (k--) {
            int id;
            cin >> id;
            if (id <= n && !bids[id].empty()) {
                auto p = make_pair(bids[id].back(), id);
                if (active.erase(p))
                    removed.push_back(p);
            }
        }
        if (active.empty())
            cout << "0 0\n";
        else {
            auto it = prev(active.end());
            int id = it->second, threshold = 0;
            if (it != active.begin())
                threshold = prev(it)->first;
            cout << id << ' ' << *upper_bound(bids[id].begin(), bids[id].end(), threshold)
                 << '\n';
        }
        for (auto p : removed)
            active.insert(p);
    }
}
