Standing Out from the Herd

For each name in the herd, count its substrings that occur in no other name.

Hard8StringString matchingTrieSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Just like people, cows like to feel they are special in some way. Farmer John's cows all come from the same breed and look alike, so they measure uniqueness by their names.

Each cow's name contains a number of substrings. For example, "amy" has substrings {a, m, y, am, my, amy}, and "tommy" has substrings {t, o, m, y, to, om, mm, my, tom, omm, mmy, tomm, ommy, tommy}.

The uniqueness factor of a name is the number of distinct substrings of that name that appear in no other cow's name. If amy were alone in a herd, her uniqueness factor would be 6. If tommy were alone, his would be 14. With both cows in the same herd, amy's factor is 3 and tommy's factor is 11.

Given a herd of cows, compute each cow's uniqueness factor.

Input

The first line contains NN (1N1051 \le N \le 10^5). Each of the next NN lines contains the name of one cow in the herd. Each name contains only lowercase letters a to z. The total length of all names does not exceed 10510^5.

Output

Print NN lines. Each line holds the uniqueness factor of one cow, in the order the names are given in the input.