using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); // Test(); } static void Solve() { var t = NN; var ans = new long[t]; var mod = 998_244_353; for (var u = 0; u < t; ++u) { var c = NList; var (n, m) = (c[0], c[1]); var n2 = n % (m * 2L); if (n2 >= m) { var zero = n2 - m; var nine = n2 - zero * 2; ans[u] = (Exp(10, nine, mod) - 1 + mod) * Exp(10, zero, mod) % mod; } else { ans[u] = (Exp(10, n2 % m, mod) - 1 + mod) % mod; } } WriteLine(string.Join("\n", ans)); } static long All(int n, int m) { var a = 1L; var b = 1L; for (var i = 0; i < n; ++i) a *= 10; for (var i = 0; i < m; ++i) b *= 10; return a % b % 998_244_353; } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }