Large Numbers are the best! The larger they are the better. As your team has condemned you to solve string problems, you try to find interest in them. What would a large string look like? Lexicographicaly large strings are simple an boring, so instead you found another way to define the size of a string.
For a given string, you want to replace all characters with digits such that the resulting number is a square number. Multiple occurrences of the same character have to be replaced with the same digit and no two different characters may be replaced by the same digit. The first character cannot be replaced by a zero. And did i forget to mention: the obtained number should obviously be as large as possible.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^5$$$). The description of the test cases follows. Each test case contains one string $$$s_i$$$ ($$$1 \leq |s_i| \leq 12$$$) consisting of lower case Latin letters.
For each testcase output the largest square number that can be obtained from the described process. If it is not possible to obtain any square, print a single integer $$$-1$$$.
4abaaaffqlcu
81-19009801
| Name |
|---|


