— I just bought Leonardo's secret notebook!
Rare-object collector Stan Ucker was thrilled, but his friend, special investigator Sarah Keptic, was unimpressed.
— How do you know it is genuine?
— Oh, at that price it must be. And it is written in the da Vinci code.
Sarah browsed a few of the pages. It was obvious to her that the code was a substitution cipher, in which each letter of the alphabet had been replaced by another letter.
— Leonardo would have written the plain text and left the encryption to his assistant, she said. And he must have supplied the substitution alphabet to use. If we are lucky, we can find it on the back cover!
She turned to the last page and, lo and behold, there was a single line containing all 26 letters of the alphabet:
QWERTYUIOPASDFGHJKLZXCVBNM
— This may be Leonardo's instruction, meaning that each A in the plain text was to be replaced by Q, each B by W, and so on. Let us see…
To their disappointment, they soon realized that this could not be the substitution used in the book. Suddenly Stan brightened.
— Maybe Leonardo really did write the substitution alphabet on the last page, and by mistake his assistant encoded that line just as he had encoded the rest of the book. So the line we have here is the result of applying some permutation twice to the ordinary alphabet!
Sarah took out her laptop and coded furiously for a few minutes. Then she turned to Stan with a sympathetic expression.
— No, that isn't it either. I am afraid you have been duped again, my friend. In all likelihood, the book is a fake.
Write a program that, given a permutation of the English alphabet, decides whether it may be the result of applying some permutation twice.
The first line contains a positive integer, the number of test cases (at most 500). Then, for each test case, there is one line containing a permutation of the 26 capital letters of the English alphabet.
For each test case, output one line containing Yes if the given permutation can result from applying some permutation twice to the original alphabet string ABC...XYZ, and No otherwise.