import sys input = sys.stdin.readline mod=998244353 for i in range(1,21): for j in range(1,21): x=pow(10,i)-1 y=pow(10,j)+1 #print(i,j,x%y) T=int(input()) for tests in range(T): N,M=map(int,input().split()) N=N%(M*2) if N<=M: print((pow(10,N,mod)-1)%mod) continue hiku=N-M ANS=(pow(10,(N-hiku),mod)-1)-(pow(10,hiku,mod)-1) print(ANS%mod)