As you have probably realized up to now that Devu is not a normal guy, he is a very weird and abnormal guy. Normally people have two hands, but Devu has three of them. So he wears three wrist watches on his hands.


Devu loves to write name of his friends on his wrist watches. So he want to attach a string corresponding to name of his friends on each wrist watch. He is a quite particular about natural beauty, so he will not attach strings such that one of the string on a watch is prefix (not necessarily proper prefix) of some other string on other watch. Also alphabet size of characters in the string is equal to first K English Alphabets. (i.e. 1 ≤ K ≤ 26).


Now Devu wonders in how many ways he can select three non empty strings of length less than or equal to N to attach with his wrist watches. As answer could be very large, he wants you to print answer modulo 10^9 + 7.


Input
First line of test case contains a single integer T corresponding to the number of test cases.
For each test case, there will be a single line containing two space separated integers N, K. 

Output
For each test case, print a single line corresponding to the answer of the problem.

Constraints

Example
Input:
3
1 2
1 3
2 2

Output:
0
6
36

Explanation
Example #1. 
There is no valid arrangement of three strings to the watches, because at least one of the string will be equal to other which will violate the property stated in the problem.

Example #2. 
There are 6 possible arrangements of the strings to the watches. 

{"a", "b", "c"} 
{"a", "c", "b"} 
{"b", "a", "c"} 
{"b", "c", "a"} 
{"c", "a", "b"} 
{"c", "b", "a"}
def power(a,b):
    x=1
    while(b):
        if(b&1):
            x=(x*a)%m
        a=(a*a)%m
        b>>=1
    return x
m=10**9+7
t=int(raw_input())
while t>0:
    t-=1
    n,k=map(int,raw_input().split())
    if k==1:
        print 0
        continue
    inv=power(k-1,m-2)
    inv=power(inv,3)
    inv=(k*inv)%m
    temp=power(k,n)
    n1=(n*n)%m
    t6=(((3*n1)%m+6*n+2)*temp)%m
    t1=(2*((temp*k)%m)*(3*n1+3*n+2))%m
    t2=(((temp*k*k)%m)*(3*n1-1))%m
    temp1=power(k,2*n+1)
    t3=(6*(n+1)*temp1)%m
    t4=(6*k*((n*temp1)%m))%m
    t5=power(k,3*n+2)
    ans=(t6+t5-t4+t3+t2-t1-2*k-2)%m
    ans=(ans*inv)%m
    print ans