#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string A[n];
    for (int i = 0; i < n; i++) {
      cin >> A[i];
    }
    map<string, int> m;
    for (int i = 0; i < n; i++) {
      m[A[i]] = m[A[i]] + 1;
    }
    map<string, int>::iterator it;
    for (it = m.begin(); it != m.end(); it++) {
      cout << it->first << " "
           << "X"
           << " " << it->second << endl;
    }
  }
}
