Problem2310-- Digit Minimization

2310: Digit Minimization

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

There is an integer nn without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.

On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.

You have to find the smallest integer Alice can get in the end, if she plays optimally.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Description of the test cases follows.

The first and the only line of each test case contains the integer nn (10≤n≤10910≤n≤109) — the integer for the game. nn does not have zeros in its decimal representation.

Output

For each test case output a single integer — the smallest integer Alice can get in the end of the game.

Sample Input Copy

3
12
132
487456398

Sample Output Copy

2
1
3

HINT

Note

In the first test case Alice has to swap 11 and 22. After that Bob removes the last digit, 11, so the answer is 22.

In the second test case Alice can swap 33 and 11312312. After that Bob deletes the last digit: 3131. Then Alice swaps 33 and 111313 and Bob deletes 33, so the answer is 11.


Source/Category