Dio Brando has set  a goal for himself of becoming the richest and the most powerful being on earth.To achieve his goals he will do anything using either manipulation,seduction or plain violence.
Only one guy stands between his goal of conquering earth ,named Jotaro Kujo aka JoJo .Now Dio has a stand (visual manifestation of life energy  i.e, special power )  “Za Warudo” ,which can stop time itself but needs to chant few words to activate the time stopping ability of the stand.There is a code hidden inside the words and if you can decipher the code then Dio loses his power.
In order to stop Dio ,Jotaro asks your help to decipher the code since he can’t do so while fighting Dio at the same time.
You will be given a string as input and you have to find the shortest substring which contains all the characters of itself and then make a number based on the alphabetical ordering of the characters.
For example : “bbbacdaddb”
shortest substring will be “bacd” and based on the alphabetical ordering
the answer is 2134
-----NOTE:-----
A substring is a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from position l to position r is
S[l;r]=SlSl+1…Sr.
-----Input :-----
The first line contains $T$,number of test cases.
The second line contains a string $S$.
-----Output:-----
For each test cases ,output the number you can get from the shortest string 
-----Constraints:-----
$1 \leq t \leq 100$
$1 \leq |S| \leq 10^6$
-----Test Cases:-----
-----Sample Input:-----
6
abcdfgh
urdrdrav
jojojojoj
bbbbaaa
cddfsccs
tttttttttttt   
-----Sample Output:-----
1234678
2118418418122
1015
21
46193
20
-----Explanation:-----
Test case 1: abcdfgh is the shortest substring containing all char of itself and the number is 1234678
# https://www.geeksforgeeks.org/smallest-window-contains-characters-string/
from collections import defaultdict

MAX_CHARS = 256

def solve(strr):
    n = len(strr)

    dist_count = len(set([x for x in strr]))

    curr_count = defaultdict(lambda: 0)
    count = 0
    start = 0
    min_len = n

    start_index = 0

    for j in range(n):
        curr_count[strr[j]] += 1

        if curr_count[strr[j]] == 1:
            count += 1

        if count == dist_count:
            while curr_count[strr[start]] > 1:
                if curr_count[strr[start]] > 1:
                    curr_count[strr[start]] -= 1

                start += 1

            len_window = j - start + 1

            if min_len > len_window:
                min_len = len_window
                start_index = start

    return str(strr[start_index: start_index + min_len])

for _ in range(int(input())):
    x = solve(input().strip())

    print(''.join(str(ord(c) - ord('a') + 1) for c in x))

# https://www.geeksforgeeks.org/smallest-window-contains-characters-string/
from collections import defaultdict

MAX_CHARS = 256

def solve(strr):
    n = len(strr)

    dist_count = len(set([x for x in strr]))

    curr_count = defaultdict(lambda: 0)
    count = 0
    start = 0
    min_len = n

    start_index = 0

    for j in range(n):
        curr_count[strr[j]] += 1

        if curr_count[strr[j]] == 1:
            count += 1

        if count == dist_count:
            while curr_count[strr[start]] > 1:
                if curr_count[strr[start]] > 1:
                    curr_count[strr[start]] -= 1

                start += 1

            len_window = j - start + 1

            if min_len > len_window:
                min_len = len_window
                start_index = start

    return str(strr[start_index: start_index + min_len])

for _ in range(int(input())):
    x = solve(input().strip())

    print(''.join(str(ord(c) - ord('a') + 1) for c in x))
