Problem Statement:
Nash, a high school student studies the concepts of Functions(Mathematics), for the first time.After learning the definitions of Domain and Range, he tries to find the number of functions possible,given the number of elements in domain and range.He comes to you for help.Can you help him with this?

Input Format:
The first line of Input contains t,the number of testcases. Then t lines follow, each line consist of two integers X and Y, indicating the size of domain and range.

Output Format:
For each testcase, output a single number which is the number of functions that can be created for given size of Domain and Range.Since the answer can be large, output the value of ans%1000000007(ie the reminder when the ans is divided by 10e9+7).

Input Constraints:
1 ≤ t ≤ 100
1 ≤ X ≤ 1000
1 ≤ Y ≤ 1000

SAMPLE INPUT
2
2 4
1 1

SAMPLE OUTPUT
16
1

Explanation

For the first input, the number of functions possible is 16.The reminder when 16 is divided by 10e9 + 7 is 16.(Quotient is 0).
Similarly, the output value for second testcase is 1.

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = input()
t = int(t)
for i in range(t):
	p = input()
	p = p.split()
	a = int(p[0])
	b = int(p[1])
	x = b**a
	print(x%1000000007)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
test = input()
test = int(test)
for i in range(test):
	l = input()
	l = l.split()
	a = int(l[0])
	b = int(l[1])
	x = b**a
	print(x%1000000007)