P=998244353 for t in range(int(input())):N,M=map(int,input().split());print(N*pow(M,N,P)*~-N*~-M*748683265%P)