Problem:


整数の差

8 個の 0 から 9 までの数字を入力したとき、その 8 個の数字を並べ替えてできる、最大の整数と最小の整数の差を出力するプログラムを作成してください。並び替えてできる数は 00135569 のように 0 から始まってもよいものとします。

Input

複数のデータセットが与えられます。１行目にデータセット数 n (n ≤ 50) が与えられます。続いて n 行のデータが与えられます。各データは 8 個の数字の並び（0 から 9 の数字）です。

Output

各データセットに対して、入力された数字を並べ替えてできる最大の整数と最小の整数の差を１行に出力して下さい。

Sample Input

2
65539010
65539010

Output for the Sample Input

96417531
96417531



Sample input:
2
65539010
65539010


Sample output:
96417531
96417531

Submission status: Wrong Answer

Solution code:
for _ in range(int(input ())):
    s=list(input ())
    s.sort ()
    Max=int("".join (s))
    s.reverse()
    Min=int("".join(s))
    print(Max-Min)

Submission status: Wrong Answer

Solution code:
m=int(input())
while m:
    n,m=input(),m-1
    if int(n)==0:break
    n=''.join(sorted(n))
    print(int(n[::-1]) - int(n))

Submission status: Accepted

Solution code:
ti = int(input())
for i in range(ti):
	x = list(input())
	print(int(''.join(sorted(x,reverse=True))) - int(''.join(sorted(x))))

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    a=''.join(sorted(list(input())))
    print(int(a[::-1])-int(a))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    tmp = [i for i in raw_input()]
    print int("".join(sorted(tmp,reverse=True))) - int("".join(sorted(tmp)))

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
    nmax=[]
    nmin=[]
    for ii in str(input()):
        nmax.append(ii)
        nmin.append(ii)
    nmax.sort(reverse=True)
    nmin.sort()
    ans=int("".join(nmax))-int("".join(nmin))
    print(ans)

Submission status: Accepted

Solution code:
n = input()
for _ in xrange(n):
    x = list(raw_input())
    x.sort()
    mi = int("".join(x))
    ma = int("".join(reversed(x)))
    print ma - mi

Submission status: Accepted

Solution code:
n = input()
for i in range(n):
    s = raw_input()
    temp = []
    for j in range(len(s)):
        temp.append(s[j])
    temp.sort()
    minNum = temp[::]
    maxNum = temp[-1::-1]
    ans = 0
    for j in range(len(maxNum)):
        ans *= 10
        ans += int(maxNum[j]) - int(minNum[j])
    print(ans)

Submission status: Accepted

Solution code:
n = input()
for i in range(n):
    s = "".join(sorted(raw_input()))
    print(int(s[::-1]) - int(s[::]))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in xrange(n):
    d = sorted([ s for s in raw_input() ])
    print int("".join(reversed(d))) - int("".join(d))

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

n = int(f.readline())
for i in range(n):
    line = f.readline().strip()
    print(int(''.join(sorted(line)[::-1])) - int(''.join(sorted(line))))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    st =  list(raw_input())
    print int(''.join(sorted(st,reverse = True)))-int(''.join(sorted(st)))

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    l = list(input())
    l.sort()
    min = int("".join(l))
    l.reverse()
    max = int("".join(l))
    
    print(max-min)

Submission status: Accepted

Solution code:
i = int(raw_input())

while (i):
	i -= 1
	st = []
	n = raw_input()

	for s in n:
		st.append(s)

	st.sort()
	a = int("".join(st))
	b = int("".join(st[::-1]))

	print b - a

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    line = raw_input()
    large = int(''.join(sorted(line, reverse=True)))
    small = int(''.join(sorted(line)))
    print large - small

Submission status: Accepted

Solution code:
n=int(raw_input())
for i in range(n):
    s=raw_input()
    l=[int(x) for x in s]
    l.sort()
    a=''.join(map(str,l))
    print int(a[::-1])-int(a)

Submission status: Accepted

Solution code:
n = int(input())
while n > 0:
  l = [i for i in input()]
  l.sort()
  m = ''
  for s in l:
    m += s
  M = ''
  l.reverse()
  for t in l:
    M += t
  print(int(M)-int(m))
  n -= 1

Submission status: Accepted

Solution code:
for i in range(input()):
    s = ''.join(sorted(list(raw_input())))
    print int(s[::-1]) - int(s)

Submission status: Accepted

Solution code:


n=int(input())
for i in range(n):
	A=[]
	string=input()
	for j in string:
		A.append(j)
	A.sort(reverse=True)
	Max="".join(A)
	A.sort()
	Min="".join(A)
	Min=int(Min)
	Max=int(Max)
	print(Max-Min)

Submission status: Accepted

Solution code:
for i in xrange(input()):
	s = sorted([s for s in raw_input()])
	print int("".join(reversed(s))) - int("".join(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(raw_input())
for i in range(n):
    line = str(raw_input())
    p = []
    for j in range(len(line)):
        p.append(int(line[j]))
    p.sort()
    x = 1
    max = 0
    min = 0
    for j in range(len(p)):
        max += p[j]*x
        min += p[len(p)-j-1]*x
        x *= 10
    print max-min

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    data = list(input())
    print(int(''.join(sorted(data, reverse=True))) - int(''.join(sorted(data))))

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    s = list(input())
    small = ""
    big = ""
    
    s.sort()
    for j in s:
        small += j

    s.reverse()
    for j in s:
        big += j

    print(int(big) - int(small))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    Max_num = ""
    Min_num = ""
    n = str(input())
    Lis = list(map(str,n))
    Min_num_lis = sorted(Lis)
    Max_num_lis = sorted(Lis)[::-1]
    for j in range(8):
        Max_num = Max_num + Max_num_lis[j]
        Min_num = Min_num + Min_num_lis[j]
    sa = int(Max_num) - int(Min_num)
    print(sa)

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    dist = [int(v) for v in str(input())]
    dmax, dmin = ''.join(map(str, sorted(dist, reverse=True))), ''.join(map(str, sorted(dist)))
    print(int(dmax)-int(dmin))

Submission status: Accepted

Solution code:
n=int(input())
for _ in range(n):
    c=[i for i in input()]
    Max=int("".join(sorted(c,reverse=True)))
    Min=int("".join(sorted(c)))
    print(Max-Min)

Submission status: Accepted

Solution code:
m=int(input())
while m:
    n,m=input(),m-1
    n=''.join(sorted(n))
    print(int(n[::-1]) - int(n))

Submission status: Accepted

Solution code:
m=int(input())
while m:
    n,m=''.join(sorted(input())),m-1
    print(int(n[::-1]) - int(n))

Submission status: Accepted

Solution code:
def join_num(arr):
    result = 0
    for i in range(len(arr)):
        result += arr[i] * 10**(7-i)
    return result
    
n = int(input())
x = [0] * n
for i in range(n):
    x[i] = str(input())

for i in range(n):
    d = []
    for c in x[i]:
        d.append(int(c))
    d.sort()
    a = join_num(d)
    d.reverse()
    b = join_num(d)
    print(b-a)

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    s = list(input().strip())
    t = sorted(s,reverse=True)
    u = sorted(s)
    dif = int(''.join(t)) - int(''.join(u))
    print(dif)

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    S = input()
    mx = int(''.join(sorted(S,reverse=True)))
    mn = int(''.join(sorted(S)))
    print(mx - mn)

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    instr = list(input())
    instr.sort()
    minno = int("".join(instr))
    maxno = int("".join(reversed(instr)))
    print(maxno-minno)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

N = int(input())

for i in range(N):
    n = int(input())
    s = str(n)
    A = list(s)

    B = sorted(A)
    C = sorted(B, reverse=True)

    b = int(''.join(B))
    c = int(''.join(C))
    print(c - b)

Submission status: Accepted

Solution code:
for i in range(int(input())):
  num = list(input())
  num.sort()
  min = int(''.join(num))
  num.reverse()
  max = int(''.join(num))
  print(max-min)

Submission status: Accepted

Solution code:
for _ in range(int(input())) :
    sample = list(input())
    Max, Min = '', ''
    sample.sort(reverse = True)
    for _ in sample : Max += _
    sample.sort()
    for _ in sample : Min += _
    print(int(Max) - int(Min))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    data = list(zip(*input()))[0]
    print(int("".join(sorted(data)[::-1])) - int("".join(sorted(data))))

Submission status: Accepted

Solution code:
def solve(data):
    result = []
    for d in data:
        temp = list(d)
        min_val = int(''.join(sorted(temp)))
        max_val = int(''.join(sorted(temp, reverse=True)))
        result.append(max_val - min_val)
    return result


if __name__ == '__main__':
    # ??????????????\???1
    24241
    num_of_set = int(input().strip())
    data = [input() for _ in range(num_of_set)]

    # ????????¨???????????¨???
    result = solve(data)
    for r in result:
        print(r)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    num = input()
    n = [i for i in num]
    n_sort = sorted(n)
    n_sort2 = sorted(n, reverse=True)
    n_sort = "".join(n_sort)
    n_sort2 = "".join(n_sort2)
    print(int(n_sort2) - int(n_sort))

Submission status: Accepted

Solution code:
# Aizu Problem 0051: Differential II
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    k = sorted([_ for _ in input().strip()])
    print(int(''.join(k[::-1])) - int(''.join(k)))

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    i = input()
    max = int(''.join(sorted(list(i), reverse=True)))
    min = int(''.join(sorted(list(i))))
    print(max - min)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    while n:
        a = ''.join(sorted(input()))
        print(int(a[::-1]) - int(a))
        n -= 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    inp = list(map(int, list(input())))
    inp_min = sorted(inp)
    inp_max = inp_min[::-1]
    print(int("".join(map(str, inp_max))) - int("".join(map(str, inp_min))))

Submission status: Accepted

Solution code:
N = int(input())

for l in range(N):
    s = input()
    n = []
    for i in range(len(s)):
        n.append(int(s[i]))
    a,b = 0,0
    n.sort()
    for i in range(len(n)):
        a *= 10
        a += n[i]

        b *= 10
        b += n[len(n)-i-1]
    print(b-a)

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 M=''.join(sorted(input()))
 print(int(M[::-1])-int(M))

Submission status: Accepted

Solution code:
w = int(input())
for i in range(w):
    n = input()
    l = sorted(n, reverse=True)
    s = sorted(n)
    print(int(''.join(l)) - int(''.join(s)))

Submission status: Accepted

Solution code:
n = int(input())
nl = []
for i in range(n):
    a = int(input())
    b = list(str(a))
    c1 = list(sorted(b))
    c2 = list(reversed(c1))
    cc1 = ''
    cc2 = ''
    for i in range(len(c1)):
        cc1 = cc1 + c1[i]
        cc2 = cc2 + c2[i]
    c1n = int(cc1)
    c2n = int(cc2)
    nl.append(abs(c1n-c2n))
    
for i in range(len(nl)):
    print(nl[i])

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    a = list(input())
    print(int("".join(sorted(a, reverse = True))) - int("".join(sorted(a))))

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
  s = list(input())
  print(int("".join(sorted(s,reverse=True))) - int("".join(sorted(s))))

Submission status: Accepted

Solution code:
diff=lambda l:int("".join(map(str,sorted(l,reverse=True))))-int("".join(map(str,sorted(l))))
[print(diff(input())) for i in range(int(input()))]

Submission status: Accepted

Solution code:
# AOJ 0051 Differential II
# Python3 2018.6.14 bal4u

n = int(input())
for i in range(n):
	a = list(input())
	print(int(''.join(sorted(a, reverse=True))) - int(''.join(sorted(a))))

Submission status: Accepted

Solution code:
for _ in [0]*int(input()):
    s = input()
    max_n = int("".join(map(str, sorted(s, reverse=True))))
    min_n = int("".join(map(str, sorted(s))))
    print(max_n - min_n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

import sys

def get_answer(param):
    param = list(param)
    param.sort()
    small = int("".join(param), 10)
    big = int("".join(param[::-1]), 10)
    return big - small
    
def main():
    params = [line.replace("\n", "") for line in sys.stdin.readlines()]
    params.pop(0)

    for param in params:
        print get_answer(param)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
for i in xrange(input()):
    num=[i for i in raw_input()]
    mi=sorted(num)
    ma=sorted(num,reverse=True)
    print int("".join(ma))-int("".join(mi))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    s = list(raw_input())
    s.sort()
    min = int("".join(s))
    s.reverse()
    max = int("".join(s))
    print("%d" % (max - min, ))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    s = sorted(raw_input())
    min = int("".join(s))
    max = int("".join(reversed(s)))
    print("%d" % (max - min, ))

Submission status: Accepted

Solution code:

import sys


def solv(nums):
    nums.sort()
    min_number = int(''.join(nums))
    nums.sort(lambda a, b: cmp(b, a))
    max_number = int(''.join(nums))
    return max_number - min_number


sys.stdin.readline()
for line in sys.stdin:
    nums = list(line.rstrip('\n'))
    print solv(nums)

Submission status: Accepted

Solution code:
n = int(raw_input())

for i in range(n):

    t = list(raw_input())

    t.sort()
    #print t
    lo = int("".join(map(str,t)))

    t.reverse()
    he = int("".join(map(str,t)))                                                                                                                                                                            
    #print he

    print he-lo

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

n = int(stdin.readline())
for _ in range(n):
    s = stdin.readline().strip()
    under = int(''.join(sorted(s)))
    upper = int(''.join(sorted(s, reverse=True)))
    print(upper - under)

Submission status: Accepted

Solution code:
n = int(raw_input())
for _ in range(n):
    s = raw_input()
    print int(''.join(sorted(s, reverse = True))) - int(''.join(sorted(s)))

Submission status: Accepted

Solution code:
n=input()
while n:
    n-=1
    a="".join(sorted(str(input())))
    print int(a[::-1])-int(a)

Submission status: Accepted

Solution code:
n=input()
while n:
    n-=1
    a="".join(sorted(raw_input()))
    print int(a[::-1])-int(a)

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    inp = raw_input()
    min = sorted(list(inp))
    max = sorted(list(inp))
    max.reverse()
    print int("".join(map(str, max))) - int("".join(map(str, min)))

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
   m = "".join(sorted(raw_input()))
   print int(m[::-1]) - int(m)

Submission status: Accepted

Solution code:
for i in range(int(raw_input())):
    s = raw_input()
    print int(''.join(sorted(s, reverse=True))) - int(''.join(sorted(s)))

Submission status: Accepted

Solution code:
for i in range(input()):
	n = list(raw_input())
	n.sort()
	mini = int("".join(sorted(n)))
	mixi = int("".join(sorted(n)[::-1]))
	print mixi - mini

Submission status: Accepted

Solution code:
n = input()
for i in xrange(n):
    num = raw_input()
    print int(''.join(sorted(num, reverse=True))) - int(''.join(sorted(num)))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    s = sorted(input())
    print(int(''.join(s[::-1])) - int(''.join(s)))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    numlst = list(input())
    numlst.sort(reverse= True)
    maxnum = [i for i in numlst]
    numlst.sort()
    minnum = [i for i in numlst]

    maxnum = int(''.join(maxnum))
    minnum = int(''.join(minnum))
    print(maxnum - minnum)

Submission status: Accepted

Solution code:
def toValue(arr):
    s = 0
    l = len(arr) - 1
    i = 0
    while l >= 0:
        s += int(arr[i]) * pow(10,l)
        i += 1
        l -= 1
    return s
    
n = int(input())

for i in range(0,n):
    s = input()
    max = []
    for j in s:
        max.append(j)
    max = sorted(max,reverse=True)
    min = sorted(max)
    print(toValue(max) - toValue(min))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n) :
    list_m = list(input())
    list_large_m = sorted(list_m, reverse = True)
    list_small_m = sorted(list_m)
    large_m = "".join(list_large_m)
    small_m = "".join(list_small_m)
    print(int(large_m) - int(small_m))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = readline().strip()
    res = int("".join(sorted(N, reverse=1))) - int("".join(sorted(N)))
    write("%d\n" % res)
T = int(readline())
for i in range(T):
    solve()

Submission status: Accepted

Solution code:
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つの数の差を求める

Submission status: Accepted

Solution code:
n = int(input())
  
for i in range(n):
    s = input().strip()
    min_str = ''.join(sorted(s))
    max_str = ''.join(sorted(s, reverse=True))
    print(int(max_str) - int(min_str))

Submission status: Accepted

Solution code:
def ans_num(num):
    min_list=(sorted(num,reverse=True))
    #print(min_list)
    max_list=sorted(num)
    #print(max_list)
    max_num=0
    min_num=0
    for i in range(len(num)):
        max_num+=max_list[i]*(10**i)
        min_num+=min_list[i]*(10**i)
    return max_num-min_num

N=int(input())
for i in range(N):
    num=list(map(int,input()))
    print(ans_num(num))

Submission status: Accepted

Solution code:
n=int(input())
while(n):
    n-=1
    a = list(input())
    a.sort()
    min = int("".join(a))
    a.sort(reverse=True)
    max = int("".join(a))
    print(max-min)

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    s = input()
    max = int("".join(sorted(s,reverse=True)))
    min = int("".join(sorted(s)))
    print(max-min)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    s = input()
    minv = ''.join(sorted(s))
    maxv = ''.join(sorted(s, reverse=1))
    print(int(maxv) - int(minv))

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

N = int(input())

for i in range(N):
    S = input()
    M = []

    for s in S:
        M.append(int(s))
    
    M.sort()

    minnum = 0
    maxnum = 0

    #print(M)

    for j, n in enumerate(M[::-1]):
        minnum += (n*10**(j))

    for j, n in enumerate(M):
        maxnum += (n*10**(j))

    #print(minnum)
    #print(maxnum)

    print(maxnum-minnum)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	n = int(input())

	for i in range(n):
		tmp = ""
		tmp2 = ""
		line = list(map(int,input()))
		ans = sorted(line)
		for j in ans:
			tmp += str(j)

		ans2 = sorted(ans,reverse=True)
		for k in ans2:
			tmp2 += str(k)

		print(int(tmp2) - int(tmp))

Submission status: Accepted

Solution code:
while True:
    try:
        N=int(input())
        for i in range(N):
            n=list(input())
            n_max=""
            n_min=""
            for j in sorted(n):
                n_min +=j
            n_max=int(n_min[::-1])
            n_min=int(n_min)
            print(n_max-n_min)
        break
    except:break

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    n = [int(i) for i in list(input())]
    min_n = sorted(n)
    max_n = sorted(n,reverse=True)
    min_ = int("".join([str(i) for i in min_n]))
    max_ = int("".join([str(i) for i in max_n]))
    dif = max_ - min_
    print(dif)

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    data = list(input())
    data.sort(reverse=True)
    max = int(''.join(d for d in data))

    data.sort()
    min = int(''.join(d for d in data))

    print(max - min)

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    num = list(map(int, list(input())))
    min_num = ''.join(list(map(str, sorted(num))))
    max_num = ''.join(list(map(str, sorted(num, reverse=True))))

    print(int(max_num) - int(min_num))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    s = list(input())
    mins = "".join(sorted(s,reverse=False))
    maxs = "".join(sorted(s,reverse=True))
    print(int(maxs)-int(mins))

Submission status: Runtime Error

Solution code:
st = []
n = raw_input()

for s in n:
	st.append(s)

s.sort()
a = int("".join())
b = int("".join(s[::-1]))

print b - a

Submission status: Runtime Error

Solution code:
i = raw_input()

while (i):
	i -= 1
	st = []
	n = raw_input()

	for s in n:
		st.append(s)

	s.sort()
	a = int("".join())
	b = int("".join(s[::-1]))

	print b - a

Submission status: Runtime Error

Solution code:
i = int(raw_input())

while (i):
	i -= 1
	st = []
	n = raw_input()

	for s in n:
		st.append(s)

	s.sort()
	a = int("".join())
	b = int("".join(s[::-1]))

	print b - a

Submission status: Runtime Error

Solution code:
i = int(raw_input())

while (i):
	i -= 1
	st = []
	n = raw_input()

	for s in n:
		st.append(s)

	st.sort()
	a = int("".join())
	b = int("".join(st[::-1]))

	print b - a

Submission status: Runtime Error

Solution code:
for i in xrange(input()):
	n = sorted(raw_input())
	x = int("".join(n[::-1]))
	for j in xrange(len(n)):
		if n[i] == "0": del n[i]
		else: break
	print x - int("".join(n))

Submission status: Runtime Error

Solution code:
#encoding=utf-8

for i in xrange(input()):
	n = sorted(raw_input())
	x = int("".join(n[::-1]))
	for j in xrange(len(n)):
		if n[i] == "0": del n[i]
		else: break
	print x - int("".join(n))

Submission status: Runtime Error

Solution code:
for _ in[0]*int(input()):
 M=''.join(sorted(input()))[::-1]
 print(int(M)-int(M[::-1].replace('0','')))

Submission status: Runtime Error

Solution code:
for _ in[0]*int(input()):
 M=''.join(sorted(input()))
 print(int(M[::-1])-int(M.replace('0','')))

Submission status: Runtime Error

Solution code:
while True:
	x = int(input())
	for i in range(x):
		li = list(input())
		li1 = int("".join(sorted(li)))
		li2 = int("".join(sorted(li,reverse=True)))
		print(li2-li1)

Submission status: Runtime Error

Solution code:
while True:
	x = int(input())
	for i in range(x):
		try:
			li = list(input())
		except:
			break
		li1 = int("".join(sorted(li)))
		li2 = int("".join(sorted(li,reverse=True)))
		print(li2-li1)