#include <iostream>#include <iomanip>#include <sstream>#include <string>#include <cstdio>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>using namespace std;#define REP(i,n) for(int i = 0; i < (n); ++i)const int maxn = 5000 + 5;int n;set<int> len;set<int>::reverse_iterator it1;set<string> s[maxn];set<string>::iterator it2;int main(){ int T; cin >> T; while (T--) { vector<string> v; cin >> n; getchar(); while (n--) { string s; getline(cin, s); for (int i = 0; i < s.length(); ++i) s[i] = tolower(s[i]); while (!s.empty()) { int p = 0; while (p < s.length() && !isalpha(s[p])) ++p; s = s.substr(p); if (s.empty()) break; p = 1; while (p < s.length() && isalpha(s[p])) ++p; v.push_back(s.substr(0, p)); s = s.substr(p); } } sort(v.begin(), v.end()); len.clear(); for (int i = 0; i < maxn; ++i) s[i].clear(); for (int i = 0; i < v.size();) { int j = i + 1; while (j < v.size() && v[j] == v[i]) ++j; if (j - i > 1) { len.insert(j - i); s[j-i].insert(v[i]); } i = j; } for (it1 = len.rbegin(); it1 != len.rend();) { int i = *it1, l = 0; stack<string> stk; for (it2 = s[i].begin(); it2 != s[i].end(); ++it2) { l = max(l, (int)it2->length()); } for (it2 = s[i].begin(); it2 != s[i].end(); ++it2) if (it2->length() == l) stk.push(*it2); if (stk.size() == 1) cout << stk.top(); else { stk.pop(); cout << stk.top(); } ++it1; if (it1 != len.rend()) cout << " "; } cout << endl; } return 0;}


