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

set<string> A[60];
set<string> B[60];
int main(){
    ios::sync_with_stdio(0);
    int t; cin>>t;
    while (t--){
        set<pair<string,string>> ans;
        int n; cin>>n;
        for (int i=0;i<n;i++) A[i].clear(),B[i].clear();
        for (int i=0;i<n;i++){
            string s; cin>>s;
            int k; cin>>k;
            while (k--){
                cin>>s; A[i].insert(s);
            }
            cin>>k;
            while (k--){
                cin>>s; B[i].insert(s);
            }
        }
        for (int i=0;i<n;i++) for (string a:A[i]) for (string b:B[i]){
            bool good=true;
            for (int j=0;j<n;j++) if (j!=i) if ((A[j].count(a))^(B[j].count(b))) good=false;
            if (good) ans.insert({a,b});
        }
        for (pair<string,string> p:ans) cout<<'('<<p.first<<','<<p.second<<')'<<endl;
        if (t) cout<<endl;
    }
    return 0;
}