#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define coutv(v) for(auto e : v) cout << e << " "; cout << endl;
#define coutvp(v) for(auto e : v) cout << e.first << " " << e.second << " "<<endl;
int main(){
int n; cin>>n;
vector<string> v(n);
for(int i=0; i<n; i++) cin>>v[i];
map<vector<int>, int> mp;
for(auto it: v){
vector<int> mpx(26);
for(auto it2: it){
mpx[it2-'a']++;
}
mp[mpx]++;
}
map<vector<int>, int> ansx;
for(auto it: mp){
vector<int> temp = it.first;
for(int i=0; i<26; i++){
for(int j=0; j<26; j++){
if(i==j) continue;
if(temp[i]==0) continue;
temp[i]--;
temp[j]++;
if(mp.find(temp)!=mp.end())
ansx[it.first] += mp[temp];
temp[i]++;
temp[j]--;
}
}
}
cout<<mp.size()<<endl;
vector<int> ans(n);
for(int i=0; i<n; i++){
vector<int> temp(26);
for(auto it: v[i]){
temp[it-'a']++;
}
ans[i] = ansx[temp];
}
for(int i=0; i<n; i++){
cout<<v[i]<<" "<<ans[i]<<endl;
}
}