#include <stdio.h>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a[11];
int testnum=0;
int n = 0;
int z1 = 999999999;
void solve(){
int x = 0, y = 0, z = 0;
int middle = n/2;
for (int i = 0; i < n; i++){
if (i < middle){
x += a[i]*pow(10.0, middle - i - 1);
}
else y += a[i]*pow(10.0, n - i - 1);
}
z = abs(x - y);
if(z1>z)z1=z;
}
int main(){
char ch;
scanf("%d ",&testnum);
for (int i = 0; i < testnum; i++){
while ((ch = getchar()) != '
'){
if (ch == ' ')continue;
a[n] = ch - '0';
n++;
}
do{
if(a[0] == 0||a[n/2]== 0)continue;
solve ();
}while (next_permutation (a, a + n));
cout << z1;
}
return 0;
}
***************************