#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
char str[32];
map< string, int > mp;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
memset(str , 0 , sizeof(str));
mp.clear();
scanf("%d",&n);
while(n--)
{
scanf("%s",str);
printf("%d\n",mp[str]++);
}
}
return 0;
}