#include <bits/stdc++.h>
using namespace std;
void Run() {
  int N{};
  map<string, int> con;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string S;
    cin >> S;
    auto it = con.find(S);
    if (it != con.end()) {
      (it->second)++;
    } else {
      con[S] = 1;
    }
  }
  for (auto const& i : con) {
    cout << i.first << " x " << i.second << "\n";
  }
}
int main() {
  Run();
  return 0;
}
