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
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	int n;
	std::vector<int> x;
	std::cin>>n;
	for(int i=1;i<=n;i++){
		int in;
		std::cin>>in;
		x.push_back(in);
	}
	for(int i=0;i<n;i++){
		std::vector<int> s;
		for(int j=1;j<=10000000;j=j*10)s.push_back(x[i]/j%10);
		std::sort(s.begin(),s.end());
		std::cout<<(s[7]-s[0])*10000000+(s[6]-s[1])*1000000+(s[5]-s[2])*100000+(s[4]-s[3])*10000+(s[3]-s[4])*1000+(s[2]-s[5])*100+(s[1]-s[6])*10+(s[0]-s[7])<<std::endl;
		s.clear();
	}
}