Byteasar, the king of Bitotia, has ordered a reform of his subjects' names. The names of Bitotians often contain repeating fragments. For example, the name Abiabuabiab contains two occurrences of the fragment abiab. Byteasar wants to replace each subject's name with a sequence of bits of the same length as the original name, and he would like the new name to reflect the repetitions of the original one.
For simplicity we treat upper-case and lower-case letters as identical. For a sequence w=w1w2…wk (of letters or bits), an integer p with 1≤p<k is called a period of w if wi=wi+p for every i=1,…,k−p. Let Per(w) denote the set of all periods of w. For example, Per(ABIABUABIAB)={6,9}, Per(01001010010)={5,8,10}, and Per(0000)={1,2,3}.
Byteasar decided that every name must be replaced by a sequence of bits that:
For example, ABIABUABIAB becomes 01001101001, BABBAB becomes 010010, and BABURBAB becomes 01000010.
Write a program that translates the subjects' current names into their new bit-sequence names.
The first line of standard input contains a single integer k, the number of names to translate (1≤k≤20). Each of the next k lines contains one name. Every name consists of at least 1 and at most 200000 upper-case letters of the English alphabet.
In tests worth 30% of the points, every name has at most 20 letters.
Print k lines. The i-th line must contain the bit sequence (a string of 0s and 1s with no separators) corresponding to the i-th input name. If no suitable bit sequence exists for some name, print XXX (without the quotation marks) on that line instead.
A bit sequence x1x2…xk is lexicographically smaller than a bit sequence y1y2…yk if there is an index i (1≤i≤k) with xi<yi and xj=yj for all j=1,…,i−1.