#include <iostream>
#include <cassert>

using namespace std;
using ll = long long;

ll mod_pow (ll a, ll x, const ll MOD) {
    assert(1 <= MOD);
    assert(0 <= x);
    a %= MOD; if (a < 0) a += MOD;

    ll res = 1;
    while (0 < x) {
        if (0 < (x & 1)) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        x >>= 1;
    }

    return res;
}

void solve (int N, int M) {
    const ll MOD = 998244353;

    if (N <= M) {
        ll ans = mod_pow(10, N, MOD) - 1;
        if (ans < 0) ans += MOD;

        cout << ans << "\n";
        return;
    }

    int width = N % (2 * M);
    if (width == 0) {
        cout << 0 << "\n";
        return;
    }

    if (width < M + 1) {
        ll ans = mod_pow(10, width, MOD) - 1;
        if (ans < 0) ans += MOD;
        cout << ans << "\n";
        return;
    }

    int zero = width - (M + 1) + 1;
    int nine = width - 2 * zero;

    ll ans = mod_pow(10, nine, MOD) - 1;
    if (ans < 0) ans += MOD;
    ans *= mod_pow(10, zero, MOD);
    ans %= MOD;

    cout << ans << "\n";
}

int main () {
    int T; cin >> T;

    for (int _ = 0; _ < T; _++) {
        int N, M; cin >> N >> M;
        solve(N, M);
    }
}