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

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t, n;
        cin >> t;
        while (t--) { 
                cin >> n;
                set<string> itas;
                set<string> engs;
                set<string> ita[n];
                set<string> eng[n];
                for (int i = 0; i < n; i++) {
                        string name;
                        int num;
                        cin >> name;
                        string ingredient;

                        cin >> num;
                        while (num--) {
                                cin >> ingredient;
                                ita[i].insert(ingredient);
                                itas.insert(ingredient);
                        }

                        cin >> num;
                        while (num--) {
                                cin >> ingredient;
                                eng[i].insert(ingredient);
                                engs.insert(ingredient);
                        }
                }
                for (auto it : itas) {
                        for (auto en : engs) {
                                bool bad_pair = false;
                                for (int i = 0; i < n; i++) {
                                        bad_pair |= ita[i].count(it) ^ eng[i].count(en); 
                                }
                                if (!bad_pair) {
                                        cout << '(' << it << ", " << en << ")\n";
                                }
                        }
                }
                cout << '\n';
        }
        return 0;
}