Do you think that being eccentric is easy? This is not the case when you're a number.
The degree of eccentricity of a -digit integer (possibly with leading zeroes) is defined as the smallest possible value of |a+b-10^N| for some -digit integers and (possibly with leading zeroes) such that S_d(X) = S_d(a) + S_d(b) holds for every digit , where S_d(P) (for 0 \le d \le 9) is the number of occurrences of digit in the decimal representation of . For example, the degree of eccentricity of amusing numbers (see problem Counting Amusing Numbers) is equal to , while the degree of eccentricity of equals (|274+719-1000|=7).
You are given some numbers of even length. Find the degree of eccentricity of each of them.
The first line contains the number of test cases (1 \le T \le 1000). Each of the next lines contains an integer of even length (possibly with leading zeroes). The total length of all numbers (excluding ) does not exceed 10^6.
For each test case, print a single line containing the degree of eccentricity of the corresponding number.
Example 1