from itertools import * exec'i=raw_input().split();i=permutations(i,len(i));print max(int(l)-int("".join(l[::-1])) for l in map("".join,i));'*input()