CF2126A.Only One Digit

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Only One Digit

You are given an integer xx. You need to find the smallest non-negative integer yy such that the numbers xx and yy share at least one common digit. In other words, there must exist a decimal digit dd that appears in both the representation of the number xx and the number yy.

Input

The first line contains an integer tt (1t10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains one integer xx (1x10001 \le x \le 1000).

Output

For each test case, output one integer yy — the minimum non-negative number that satisfies the condition.

Note

In the first test case, the numbers 66 and 66 share the common digit '6'. Moreover, there is no natural number smaller than this that shares a common digit.

In the second test case, the numbers 66 and 9696 share the common digit '6'.

Samples

5
6
96
78
122
696
6
6
7
1
6

在线编程 IDE

建议全屏模式获得最佳体验