#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int maxn=100+100000;
map<ull,int> mp;
char s[50];
ull BKDRHash(char* s)
{
ull seed=133331;
ull hashv=0;
while(*s)
{
hashv=hashv*seed+(*s++);
}
return (hashv & 0x7FFFFFFF);
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%s",s);
int len=strlen(s);
sort(s,s+len);
ull k=BKDRHash(s);
printf("%d\n",mp[k]);
mp[k]++;
}
return 0;
}