#include <bits/stdc++.h>
#include <unordered_set>

// https://atcoder.jp/contests/abc192/tasks/abc192_c

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()


int main(){
    string N;
    ll K;
    cin >> N >> K;

    ll tmp = stoll(N);
    int digit = N.size();

    rep(i, K){
        int num;
        vi t(digit);
        rep(j, digit){
            num = tmp % 10;
            t.at(j) = num;
            tmp /= 10;
        }
        vi g1(t.size()), g2(t.size());
        g1 = t;
        sort(ALL(g1));
        g2 = g1;
        reverse(ALL(g2));
        ll gn1 = 0, gn2 = 0;
        int d = 1;
        rep(j, g1.size()){
            gn1 += d * g1.at(j);
            gn2 += d * g2.at(j);
            d *= 10;
        }
        tmp = gn1 - gn2;
        string str = to_string(tmp);
        digit = str.size();
    }    

    cout << tmp << endl;
    
}
#include <bits/stdc++.h>

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 1e6+5;
const int mod = 1e9+7;
/**
Read problem statement carefully
5
2 6
0 0
1000000 1000000
12345 67890
0 1000000

**/

LL f(int a, int l){
    return a - 2*l + 1;
}

void solve(){
    int l, r;
    cin >> l >> r;
    LL res = 0;
    // (2*l + r) * (r - 2*l + 1) / 2
    /*for(int a = 2*l; a <= r; ++a){
        res += a - 2*l + 1;
    }*/
    if(2*l > r){
        cout << 0 << "\n";
        return;
    }
    cout << (f(2*l, l) + f(r, l)) * (r-2*l+1) / 2 << "\n";
}

int main()
{
    Fast;
    //init();
    louisfghbvc
        solve();
    return 0;
}

/**
enjoy the problem.
**/
