#include #include #include #include using namespace std; const int Maxn = 1100000; struct trie_node { int child[30]; int sum; void clear (){ memset ( child, -1, sizeof (child) ); sum = 0; } }tr[Maxn]; int tot; int rt; int n; char s[50]; int len; int tj ( int now, int l ){ if ( now == -1 ) return 0; if ( l == len+1 ) return tr[now].sum; return tj ( tr[now].child[s[l]-'A'], l+1 ); } void update ( int &now, int l ){ if ( now == -1 ){ now = ++tot; tr[now].clear (); } if ( l == len+1 ){ tr[now].sum ++; return; } update ( tr[now].child[s[l]-'A'], l+1 ); } int main (){ int i, j, k; scanf ( "%d", &n ); tot = 1; rt = 1; tr[tot].clear (); for ( i = 1; i <= n; i ++ ){ scanf ( "%s", s+1 ); len = strlen (s+1); sort ( s+1, s+len+1 ); printf ( "%d\n", tj ( rt, 1 ) ); update ( rt, 1 ); } return 0; }