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