//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lg = unsigned long long; #define TEST clog << "TEST" << endl #define IINF 2147483647 #define LLINF 9223372036854775807LL //#define AMARI 1000000007 #define AMARI 998244353 #define TEMOTO ((sizeof(long double) == 16) ? false : true) #define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000) #define el '\n' #define El '\n' #define MULTI_TEST_CASE true void solve(void) { lg n; int x; cin >> n >> x; vector v(18, 0); for (int i = 0; i < x; i++)v[17 - i] = 1; lg ans = 0; do { lg temp = 1,zyuu = 10; for (int i = 0; i < 18; i++) { if (v[i]) { //この桁で繰り上がるのが何通りあるか求める lg zyougen = min(n, zyuu); lg x = zyougen - zyuu / 2; x %= AMARI; x--; if (zyougen <= zyuu / 2) { temp = 0; break; } //if(v[0])clog << (x % AMARI); temp *= (((x + 1) * (2 * x + 1)) % AMARI); temp %= AMARI; } else { lg zyougen = min(n, zyuu); if (zyougen < zyuu / 2)continue; lg x = zyougen - zyuu / 2; x %= AMARI; temp *= (((zyougen % AMARI) * (zyougen % AMARI)) % AMARI) - (((x + 1) * (2 * x + 1)) % AMARI); //この桁で繰り上がらないのが何通りあるか求める } zyuu *= 10uLL; } ans += temp; ans %= AMARI; //clog << ans << el; } while (next_permutation(v.begin(), v.end())); cout << ans << el; return; } void calc(void) { vector v = { 0,0,0,1,1 }; do { for (int i = 0; i < 5; i++) { cout << v[i]; } cout << el; } while (next_permutation(v.begin(), v.end())); return; } int main(void) { cin.tie(nullptr); ios::sync_with_stdio(false); int t = 1; if (MULTI_TEST_CASE)cin >> t; while (t--) { solve(); } //calc(); return 0; }