When you enter 8 numbers from 0 to 9, write a program that outputs the difference between the largest integer and the smallest integer that can sort the 8 numbers. The number that can be sorted may start from 0, such as 00135569.



Input

Given multiple datasets. The number of datasets n (n ≤ 50) is given on the first line. Then n rows of data are given. Each data is a sequence of 8 numbers (0 to 9 numbers).

Output

For each dataset, output the difference between the largest and smallest integers that can be rearranged in the entered numbers on one line.

Example

Input

2
65539010
65539010


Output

96417531
96417531
for _ in range(int(input())): #与えられたデータセット回繰り返す
    str0 = input() #標準入力
    int1 = [int(a) for a in str0] #入力された値を数値化する
    int1.sort() #リストの数を小さい順に並べる
    int2 = sorted(int1,reverse=True) #大きい順に並べたリストの作成
    str1 = [str(b) for b in int1] #"join"を使うために文字になおす
    str2 = [str(c) for c in int2] #上記同様
    strm1 = ''.join(str1) #リストを1個の文字列にする
    strm2 = ''.join(str2) #上記同様
    print(int(strm2) - int(strm1)) #2つの数の差を求める
