Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 
Zombies zombies everywhere!! 
In a parallel world of zombies, there are N zombies. There are infinite number of unused cars, each of same model only differentiated by the their colors. The cars are of K colors.

A zombie parent can give birth to any number of zombie-children (possibly zero), i.e. each zombie will have its parent except the head zombie which was born in the winters by combination of ice and fire.

Now, zombies are having great difficulties to commute to their offices without cars, so they decided to use the cars available. Every zombie will need only one car. Head zombie called a meeting regarding this, in which he will allow each zombie to select a car for him.

Out of all the cars, the head zombie chose one of cars for him. Now, he called his children to choose the cars for them. After that they called their children and so on till each of the zombie had a car. Head zombie knew that it won't be a good idea to allow children to have cars of same color as that of parent, as they might mistakenly use that. So, he enforced this rule during the selection of cars.

Professor James Moriarty is a criminal mastermind and has trapped Watson again in the zombie world. Sherlock somehow manages to go there and met the head zombie. Head zombie told Sherlock that they will let Watson free if and only if Sherlock manages to tell him the maximum number of ways in which the cars can be selected by N Zombies among all possible hierarchies. A hierarchy represents parent-child relationships among the N zombies. Since the answer may be large, output the answer modulo 10^{9} + 7. Sherlock can not compute big numbers, so he confides you to solve this for him.

------ Input ------ 

The first line consists of a single integer T, the number of test-cases.

Each test case consists of two space-separated integers N and K, denoting number of zombies and the possible number of colors of the cars respectively.

------ Output ------ 

For each test-case, output a single line denoting the answer of the problem.

------ Constraints ------ 

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{9}$
$1 ≤ K ≤ 10^{9}$

------ Subtasks ------ 

Subtask #1 : (10 points)

1 ≤ T ≤ 20
1 ≤ N, K ≤ 10

Subtask 2 : (20 points) 

1 ≤ T ≤ 10
1 ≤ N, K ≤ 10000

Subtask 3 : (70 points) 

1 ≤ T ≤ 100
1 ≤ N, K ≤ 10^{9}

----- Sample Input 1 ------ 
2
2 2
3 3
----- Sample Output 1 ------ 
2
12

Difficulty: MEDIUM

Solutions:
Testcases = int(input())
for Testcase in range(0, Testcases):
	List = input().split()
	N = int(List[0])
	K = int(List[1])
	C = 10 ** 9 + 7
	Result = K * pow(K - 1, N - 1, C) % C
	print(Result)


MOD = 1000000007

def fast_exp(base, exp):
	res = 1
	while exp:
		if exp & 1:
			res = res * base % MOD
		base = base * base % MOD
		exp = exp >> 1
	return res
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		if n == 1:
			print('1')
		else:
			print('0')
		continue
	ans = k
	ans = ans * fast_exp(k - 1, n - 1) % MOD
	print(ans)


m = 10 ** 9 + 7
for tt in range(int(input())):
	(n, k) = map(int, input().split())
	z = k - 1
	aa = k % m
	print(aa * pow(z, n - 1, m) % m)


t = int(input())
for i in range(1, t + 1):
	numbers = list(map(int, input().split()))
	n = numbers[0]
	k = numbers[1]
	k1 = k % (10 ** 9 + 7)
	k2 = pow(k - 1, n - 1, 10 ** 9 + 7)
	temp = k1 * k2 % (10 ** 9 + 7)
	print(temp)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(k * pow(k - 1, n - 1, 1000000007) % 1000000007)


t = int(input())
for i in range(t):
	(n, k) = tuple(map(int, input().split()))
	ans = pow(k - 1, n - 1, 1000000007)
	ans = ans % 1000000007 * (k % 1000000007) % 1000000007
	print(ans)


mod = 1000000007
for _ in range(int(input())):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	print(k * pow(k - 1, n - 1, mod) % mod)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mod = 1000000007
	print(k % mod * pow(k - 1, n - 1, mod) % mod)


def mod_pow(base, exp, mod):
	result = 1
	while exp:
		if exp & 1:
			result = result * base % mod
		exp >>= 1
		base = base * base % mod
	return result

def solve(n, k, mod):
	return k * mod_pow(k - 1, n - 1, mod) % mod
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k, 10 ** 9 + 7))


def pow_mod(x, y, z):
	number = 1
	while y:
		if y & 1:
			number = number * x % z
		y >>= 1
		x = x * x % z
	return number
t = int(input())
MOD = 10 ** 9 + 7
for _ in range(0, t):
	(n, k) = map(int, input().split())
	if k == 1:
		if n == 1:
			print(1)
		else:
			print(0)
	elif n == 1:
		if k == 1:
			print(1)
		else:
			print(n * k)
	else:
		ans = 1
		ans = k % MOD * int(pow_mod(k - 1, n - 1, MOD)) % MOD
		print(ans)


a = int(input())
for i in range(a):
	(y, x) = map(int, input().split())
	print(x * pow(x - 1, y - 1, 10 ** 9 + 7) % (10 ** 9 + 7))


mod = int(1000000007)

def pow1(x, y):
	temp = 0
	if y == 0:
		return 1
	temp = pow1(x, int(y / 2)) % mod
	if y % 2 == 0:
		temp = temp * temp % mod
		return temp
	else:
		temp = temp * temp % mod
		temp = x * temp % mod
		return temp
t = int(input())
while t != 0:
	t -= 1
	(x, y) = map(int, input().split())
	print(y * pow1(y - 1, x - 1) % mod)


t = int(input())
ans = []
for i in range(t):
	x = list(map(str, input().split()))
	n = int(x[0])
	k = int(x[1])
	temp_old = int(k % (10 ** 9 + 7) * pow(k - 1, n - 1, 10 ** 9 + 7) % (10 ** 9 + 7))
	ans.append(temp_old)
for x in ans:
	print(x)


def mult(n, k):
	if n == 0:
		return 1
	if n == 1:
		return k
	else:
		pcount = 1
		ans = k
		while True:
			if pcount * 2 > n:
				break
			ans = ans % constant * (ans % constant) % constant
			pcount = pcount * 2
		return ans % constant * (mult(n - pcount, k) % constant) % constant

def mult2(n, k):
	return pow(k, n, constant)
constant = pow(10, 9) + 7

def answer():
	for t in range(int(input())):
		(N, K) = [int(x) for x in input().split()]
		if N == 1:
			print(K)
		elif N != 1 and K == 1:
			print(0)
		elif N != 1 and K != 1:
			print(K * (mult(N - 1, K - 1) % constant) % constant)
	return
answer()


import math
import sys

def main():
	m = int(input())
	for i in range(1, m + 1, 1):
		(n, k) = map(int, sys.stdin.readline().split())
		to = 1
		to = pow(k - 1, n - 1, 1000000007)
		to = to * k % 1000000007
		print(to)
main()


md = int(1000000000.0 + 7)
T = int(input())
while T > 0:
	T -= 1
	(n, k) = map(int, input().split())
	ans = k * pow(k - 1, n - 1, md) % md
	print(ans)


for _ in range(int(input())):
	nk = [int(i) for i in input().split()]
	n = nk[0]
	k = nk[1]
	if n == 1 and k == 1:
		print(1)
		continue
	ans = k * pow(k - 1, n - 1, 1000000007) % 1000000007
	print(ans)


m = 10 ** 9 + 7

def Kode(x, e, m):
	X = x
	E = e
	Y = 1
	while E > 0:
		if E % 2 == 0:
			X = X * X % m
			E = E / 2
		else:
			Y = X * Y % m
			E = E - 1
	return Y
for tt in range(int(input())):
	(n, k) = map(int, input().split())
	z = k - 1
	a = k % m * Kode(z, n - 1, m) % m
	print(a)


def fast_power(a, n):
	result = 1
	value = a
	power = n
	while power > 0:
		if power % 2 == 1:
			result = result * value % 1000000007
		value = value * value % 1000000007
		power = int(power // 2)
	return result
t = int(input())
while t > 0:
	x = input().split()
	n = int(x[0])
	k = int(x[1])
	ans = k * fast_power(k - 1, n - 1)
	print(ans % 1000000007)
	t = t - 1


import math
T = int(input())
for i in range(0, T):
	(a, b) = map(int, input().split())
	x = pow(b - 1, a - 1, 1000000007)
	x = x * b
	x = x % 1000000007
	print(x)


import math
T = int(input())
for i in range(0, T):
	(n, k) = map(int, input().split())
	a = pow(k - 1, n - 1, 1000000007)
	a = a * k % 1000000007
	print(a)


def f(x, e, m):
	X = x
	E = e
	Y = 1
	while E > 0:
		if E % 2 == 0:
			X = X * X % m
			E = E / 2
		else:
			Y = X * Y % m
			E = E - 1
	return Y
import math
testCases = int(input())
for c in range(0, testCases):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	temp = f(k - 1, n - 1, 1000000007)
	temp2 = k % 1000000007
	answer = temp * temp2 % 1000000007
	print(answer)


M = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(m * pow(m - 1, n - 1, M) % M)


import sys

def long_pow(x, y, z):
	number = 1
	while y:
		if y & 1:
			number = number * x % z
		y >>= 1
		x = x * x % z
	return number
test_cases = int(input())
for test in range(test_cases):
	(n, m) = map(int, input().split())
	ans = m * long_pow(m - 1, n - 1, 1000000007) % 1000000007
	print(ans)


def power(a, b, m):
	if a == 0:
		return 0
	if b == 0:
		return 1
	p = power(a, b // 2, m) % m
	p = p * p % m
	if b % 2 == 1:
		p = p * a % m
	return p
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	ans = power(k - 1, n - 1, 1000000007)
	ans = ans * k
	ans = ans % 1000000007
	print(ans)


def gao(x, y):
	if x == 1:
		return y
	if y == 1:
		return 0 if x > 1 else 1
	m = 10 ** 9 + 7

	def p(x, e):
		if e == 0:
			return 1
		q = p(x, e // 2)
		q = q * q % m
		return q * x % m if e % 2 == 1 else q
	return p(y - 1, x - 1) * y % m
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	print(gao(x, y))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	m = 10 ** 9 + 7
	ans = k % m * pow(k - 1, n - 1, m) % m
	print(ans)


x = int(input())
mod = 1000000007
for q in range(x):
	y = input().split(' ')
	n = int(y[0])
	k = int(y[1])
	ans = pow(k - 1, n - 1, mod)
	ans = k * ans % mod
	print(ans)


def power(x, y):
	if y == 0:
		return 1
	if y == 1:
		return x
	temp = power(x, y // 2)
	if y % 2 == 0:
		return temp * temp % 1000000007
	else:
		return x * temp * temp % 1000000007
t = int(input())
b = []
for i in range(0, t):
	a = []
	a = list(map(int, input().split()))
	tot = power(a[1] - 1, a[0] - 1)
	t = str(tot * a[1] % 1000000007)
	b.append(t)
print('\n'.join(b))


t = int(input())
mod = 1000000007
for T in range(t):
	l = list(map(int, input().split()))
	n = l[0]
	k = l[1]
	ans = pow(k - 1, n - 1, mod)
	ans *= k
	ans %= mod
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(k * pow(k - 1, n - 1, 10 ** 9 + 7) % (10 ** 9 + 7))


def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x
	else:
		a = power(x, y // 2) % 1000000007
		if y % 2 == 0:
			return a * a % 1000000007
		else:
			return a * a * x % 1000000007
for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	p = power(k - 1, n - 1)
	ans = p * k
	print(ans % 1000000007)


def modpow(b, e, mod):
	res = 1
	b %= mod
	while e:
		if e & 1:
			res = res * b % mod
		b = b * b % mod
		e >>= 1
	return res
t = int(input())
mod = int(1000000000.0) + 7
for i in range(t):
	(n, k) = map(int, input().split(' '))
	t = k * modpow(k - 1, n - 1, mod)
	t %= mod
	print(t)


t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	m = 1000000007
	k = k * pow((k - 1) % m, (n - 1) % m, 1000000007)
	print(k % m)


t = int(input())
while t != 0:
	t = t - 1
	(n, k) = [int(y) for y in input().split()]
	ans = pow(k - 1, n - 1, 1000000007) * k % 1000000007
	print(ans)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	x = pow(k - 1, n - 1, 10 ** 9 + 7)
	y = k % (10 ** 9 + 7)
	print(x * y % (10 ** 9 + 7))
	t = t - 1


m = 1000000007

def multiply(n, k):
	if k == 0:
		return 1
	mul = multiply(n, k // 2) % m
	if k % 2 == 1:
		return n * mul * mul
	else:
		return mul * mul

def number(n, k):
	ans = k
	if n - 1 == 0:
		ans = ans * 1
	elif k - 1 == 0:
		ans = ans * 0
	else:
		ans = ans * multiply(k - 1, n - 1)
		ans = ans % m
	return ans
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	print(number(n, k))


for i in range(int(input())):
	(x, y) = map(int, input().split())
	m = 10 ** 9 + 7
	ans = y % m * pow(y - 1, x - 1, m) % m
	print(ans)


prime = 10 ** 9 + 7
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	print(k % prime * pow(k - 1, n - 1, prime) % prime)
	t -= 1


for _ in range(int(input())):
	(m, n) = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	print(n * pow(n - 1, m - 1, mod) % mod)


t = int(input())
while t:
	(n, k) = (int(x) for x in input().split())
	m = 10 ** 9 + 7
	ans = k % m * pow(k - 1, n - 1, m) % m
	print(ans)
	t = t - 1


def f(x, e, m):
	X = x
	E = e
	Y = 1
	while E > 0:
		if E % 2 == 0:
			X = X * X % m
			E = E / 2
		else:
			Y = X * Y % m
			E = E - 1
	return Y
for tests in range(int(input())):
	[N, K] = [int(i) for i in input().split()]
	N -= 1
	p = K
	p = p * f(K - 1, N, 10 ** 9 + 7) % (10 ** 9 + 7)
	print(p)


def power(a, b, n):
	r = 1
	while b > 0:
		if b & 1 == 1:
			r = r * a % n
		b = b // 2
		a = a * a % n
	return r % n
t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	x = k
	n -= 1
	k -= 1
	print(power(k, n, 1000000007) * x % 1000000007)