def fast_exponentiation(a, b, n): result = 1 a %= n while b > 0: # 指数を二進数で表現し、各桁ごとに処理 if b % 2 == 1: result = (result * a) % n a = (a * a) % n b //= 2 return result for _ in range(int(input())): n,m=map(int,input().split()) if n%(2*m)==0: print(0) else: print(((fast_exponentiation(10,n%(2*m),998244353))-1)%998244353)