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

typedef pair<string,string> pss;

int main() {
  ios::sync_with_stdio(0);
  int t; cin >> t;
  while (t--) {
    set<string> fl[60];
    set<string> fa;
    set<string> nl[60];
    set<string> na;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
      string s; cin >> s;
      int m; cin >> m;
      for (int j = 0; j < m; j++) {
        cin >> s;
        fl[i].insert(s);
        fa.insert(s);
      }
      int l; cin >> l;
      for (int j = 0; j < l; j++) {
        cin >> s;
        nl[i].insert(s);
        na.insert(s);
      }
    }
    for (string fi : fa) {
      for (string ni : na) {
        bool ok = true;
        for (int i = 0; i < n; i++) {
          if (fl[i].count(fi) != nl[i].count(ni)) {
            ok = false;
            break;
          }
        }
        if (ok)
          cout << "(" << fi << ", " << ni << ")\n";
      }
    }
    if (t)
      cout << "\n";
  }
  return 0;
}