1690 - A Simple Number Problem

Time Limit: 5s Memory Limit: 512MB

Submissions: 30 Solved: 3
Description

Mathematics knowledge is vital in Artificial Intelligence Area, Minieye wants to employ those who are good at Mathematics such as ACMers. Here is a problem related to mathematics Given 2n digits from 1 to 9, your task is to compose two integers A, B of length n, to minimize the value of |A+B-10n|. In this situation, leading zeros is legal.

Input

There are several cases, first is the number of cases T. (T = 100000).

For each case, there is only one line contains a string of 2n digits.(n<=18)

Output

For each case, output the minimum value in a line.

Sample Input
3
9820
192747
000001
Sample Output
0
7
900
Hint

Explanation for the samples:

|98 + 02 - 100| = 0

|274 + 719 - 1000| = 7

|100 + 000 - 1000| = 900

 

Source
YY