for _ in range(int(input())): n,m=map(int,input().split()) if n%(2*m)==0: print(0) else: print(int('9'*(n%(2*m)))%998244353)