The idea proposed by Guy Gervais was so fruitful that it allows to create more than one problem from it. Here is the simpler one.
In many natural languages we can find some pairs of words which could be transformed to each other by changing the order of letters. I.e. they consist of the same set of letters, for example:
cat - act take - teak ate - eat - tea
Such words are called anagrams and as we see in the third example sometimes there are more than two words.
Your task is to find out the amount of anagrams for given word by the dictionary.
Dictionary file contains a list of english words, one per line. It was taken from Ubuntu linux distribution and stripped of words containing capital letters, apostrophes and non-english letters.
Input data will contain the number of test-cases in the first line.
Next lines will contain a single word each.
Answer should contain the number of anagrams for each word (not including the word itself).
input data: 3 bat coal lots answer: 1 1 2