Q=int(input()) mod=1000000007 for i in range(Q): a,b=map(int,input().split()) this1=1 for j in range(1,a+1): this=0 for k in range(1,b+1): this+=k*j this%=mod this1*=this this1%=mod print(this1)