数据好水。。。
#include <bits/stdc++.h>
using namespace std;
#define ls st<<1
#define rs st<<1|1
#define LL long long
const int MAXN= (int) 26;
int arr[MAXN];
bool check(char ch) {
return ch>='A'&&ch<='Z';
}
int fz(int x) {
int a[4];
for (int i = 0; i < 4; ++i)
a[i] = x%10, x/=10;
sort(a, a+4);
for (int i = 0; i < 3; ++i)
x += a[i], x*=10;
x += a[3];
return x;
}
int fz_1(int x) {
int a[4];
for (int i = 0; i < 4; ++i)
a[i] = x%10, x/=10;
sort(a, a+4, greater<int>());
for (int i = 0; i < 3; ++i)
x += a[i], x*=10;
x += a[3];
return x;
}
int main() {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int x, y, k;
map<int, int> mp;
cin >> x >> k;
mp[x]++;
for (int i = 1; i <= k; ++i) {
x = abs(fz_1(x)-fz(x));
}
cout << x << endl;
}
return 0;
}