P13810 [CodeChef] devhand
提高-
题目描述

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"}

输入格式

见题面

输出格式

见题面

样例输入
3 1 2 1 3 2 2
样例输出
0 6 36