#include <bits/stdc++.h>
using namespace std;
template <class T>
void printArray(vector<T> arr) {
  for (T a : arr) cout << a << " ";
  cout << '\n';
}
void printVerdict(bool verdict) { cout << (verdict ? "YES" : "NO") << '\n'; }
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> count;
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    if (count.find(temp) == count.end())
      count[temp] = 1;
    else
      count[temp]++;
  }
  auto it = count.begin();
  while (it != count.end()) {
    cout << it->first << " x " << it->second << '\n';
    it++;
  }
}
