mod=1e9+7
for _ in range(int(input())):
    n,k=[int(x) for x in input().split()]
    print(pow(n,k)%mod)


#import sys
#import math
#sys.stdout=open("C:/Users/pipal/OneDrive/Desktop/VS code/python/output.txt","w")
#sys.stdin=open("C:/Users/pipal/OneDrive/Desktop/VS code/python/input.txt","r")
t=int(input())
for i in range(t):
   # n=int(input())
    c=0
    mod=10**9+7
    n,k=(map(int,input().split()))
    maxi=(2**k)-1
    half=maxi//2
    f=(n%mod)+(n%mod)*((n-1)%mod)*(half%mod)
    print(f%mod)
   # print(half)


t=input()
tt=int(t)
while tt:
    n,k=input().split()
    q=int(k)
    ans=1
    while q:
        q-=1
        ans=ans*int(n)
    print(ans)
    tt-=1;


for _ in range(int(input())):
    n, k = [int(x) for x in input().split()]
    print((n**k)/1000000007)


for _ in range(0,int(input())):
  l, power = map(int, input().split())
  count = 0
  n = 2**power
  choices = l+1
  for i in range(0,2**power):
    if(i&1 == 0):
      count += choices
  print(count%(10**9+7))


t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    mod = 10**9 + 7
    ans = n * 2**k // 2
    print(ans % mod)


import math
n=int(input())
a=[]
b=1
for i in range(1,n):
    if math.gcd(n,i)==1:
        a.append(i)
for i in range(len(a)):
    b=(b*a[i])%n
if b!=1:
    a.remove(b)
print(len(a))
print(*a)


try:
    import sys
#     from __future__ import division, print_function
#     import bisect
    import math
    # import heapq
    import collections
#     i_m = 9223372036854775807
    M = 10**9+7

    # def matrix(n):
    #     #matrix input
    #     return [list(map(int, input().split()))for i in range(n)]

#     def string2intlist(s):
#         return list(map(int, s))

#     def calculate_sum(a, N):  # sum of a to N
#         # Number of multiples
#         m = N / a
#         # sum of first m natural numbers
#         sum = m * (m + 1) / 2
#         # sum of multiples
#         ans = a * sum
#         return ans

#     def series(N):
#         return (N*(N+1))//2

#     def count2Dmatrix(i, list):
#         return sum(c.count(i) for c in list)

#     def modinv(n, p):
#         return pow(n, p - 2, p)

#     def nCr(n, r):
#         i = 1
#         while i < r:
#             n *= (n - i)
#             i += 1
#         return n // math.factorial(r)

#     def GCD(x, y):
#         x = abs(x)
#         y = abs(y)
#         if(min(x, y) == 0):
#             return max(x, y)
#         while(y):
#             x, y = y, x % y
#         return x

#     def LCM(x, y):
#         return (x * y) // GCD(x, y)

    # def Divisors(n):
    #     l = []
    #     for i in range(1, int(math.sqrt(n) + 1)):
    #         if (n % i == 0):
    #             if (n // i == i):
    #                 l.append(i)
    #             else:
    #                 l.append(i)
    #                 l.append(n//i)
    #     return l

    # def isprime(n):
    #     for i in range(2, int(math.sqrt(n))+1):
    #         if n % i == 0:
    #             return False
    #     return True

    # def isprime(n):
    #     if(n <= 1):
    #         return False
    #     if(n <= 3):
    #         return True
    #     if(n % 2 == 0 or n % 3 == 0):
    #         return False
    #     for i in range(5,int(math.sqrt(n) + 1), 6):
    #         if(n % i == 0 or n % (i + 2) == 0):
    #             return False
    #     return True
    # def SieveOfEratosthenes(n):
    #     prime = [True for i in range(n+1)]
    #     p = 2
    #     while (p * p <= n):
    #         if (prime[p] == True):
    #             for i in range(p * p, n+1, p):
    #                 prime[i] = False
    #         p += 1
    #     f = []
    #     for p in range(2, n+1):
    #         if prime[p]:
    #             f.append(p)
    #     return f

#     q = []

#     def dfs(n, d, v, c):
#         global q
#         v[n] = 1
#         x = d[n]
#         q.append(n)
#         j = c
#         for i in x:
#             if i not in v:
#                 f = dfs(i, d, v, c+1)
#                 j = max(j, f)
#                 # print(f)
#         return j
#     # d = {}

#     def knapSack(W, wt, val, n):
#         K = [[0 for x in range(W + 1)] for x in range(n + 1)]
#         for i in range(n + 1):
#             for w in range(W + 1):
#                 if i == 0 or w == 0:
#                     K[i][w] = 0
#                 elif wt[i-1] <= w:
#                     K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w])
#                 else:
#                     K[i][w] = K[i-1][w]

#         return K[n][W]

    # def modularExponentiation(x, n):
    #     if(n == 0):
    #         return 1
    #     elif (n % 2 == 0):  # n is even
    #         return modularExponentiation((x*x) % M, n//2)
    #     else:  # n is odd
    #         return (x * modularExponentiation((x * x) % M, (n - 1) // 2)) % M

     # def powerOftwo(n):
    #     return n and (not (n & (n-1)))

#     def modInverse(a, m):
#         m0 = m
#         y = 0
#         x = 1

#         if (m == 1):
#             return 0

#         while (a > 1):

#             # q is quotient
#             q = a // m

#             t = m

#             # m is remainder now, process
#             # same as Euclid's algo
#             m = a % m
#             a = t
#             t = y

#             # Update x and y
#             y = x - q * y
#             x = t

#         # Make x positive
#         if (x < 0):
#             x = x + m0

#         return x
    # temp = [0]*101
#     def mapi(l,r):
#         idx = -1
#         val = -1
#         if(l > r):
#             return 0
#         if(l == r):
#             return l
#         for l in range(l,r+1):
#             if temp[l]>val:
#     	        idx = l
#     	        val = temp[l]
#         return idx

    def solve():
        n,k = map(int,input().split())
        # lst = list(map(int,input().split()))
        factor = 2**k
        ans = 1
        for i in range(n):
            ans = (ans*factor)%M
        return (ans*2)%M

    test = int(input())
    count1 = 1
    while count1<=test:
        ans = solve()
        sys.stdout.write(str(ans)+"\n")
        # sys.stdout.write("Case #"+str(count1)+": "+str(ans)+"\n")
        count1 += 1
except EOFError:
    print(" ")


t=int(input())
while t>0:
    n,k=map(int,input().split())

    ans=1
    for j in range(k):
        ans=ans*(n%(10**9+7))
    t-=1


def ints():
    return list(map(int, input().split()))

def case():
    n, k = ints()
    print(n, k)
    return pow(n, k, 10 ** 9 + 7)

t, = ints()
for i in range(t):

    print(case())


from math import ceil, floor
for _ in range(int(input())):
	n, k = map(int, input().split())
	# a = list(map(int, input().split()))

	if n == 1:
		print(1)
		continue
	else:
		p = 2*k - 2
		ans = 2**p
		ans %= (10**9 + 7)
		print(ans)#(2**(k-1))**2 % (10**9 + 7))


# cook your dish here
from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
# import numpy as np
from queue import Queue, PriorityQueue
from heapq import *
from statistics import *
from math import sqrt
import fractions
import copy
from copy import deepcopy
import sys
import io

sys.setrecursionlimit(10000)
import math
import os
import bisect
import collections

mod = int(pow(10, 9)) + 7
import random
from random import *
from time import time;

def ncr(n, r, p=mod):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p

def normalncr(n, r):
    r = min(r, n - r)
    count = 1;
    for i in range(n - r, n + 1):
        count *= i;

    for i in range(1, r + 1):
        count //= i;
    return count

inf = float("inf")
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
    adj[a].add(b)
    adj[b].add(a)

def bfs(v):
    q = Queue()
    q.put(v)
    visited[v] = 1
    while q.qsize() > 0:
        s = q.get_nowait()
        print(s)
        for i in adj[s]:
            if visited[i] == 0:
                q.put(i)
                visited[i] = 1

def dfs(v, visited):
    if visited[v] == 1:
        return;
    visited[v] = 1

    print(v)
    for i in adj[v]:
        dfs(i, visited)

# a9=pow(10,6)+10
# prime = [True for i in range(a9 + 1)]
# def SieveOfEratosthenes(n):
#     p = 2
#     while (p * p <= n):
#         if (prime[p] == True):
#             for i in range(p * p, n + 1, p):
#                 prime[i] = False
#         p += 1
# SieveOfEratosthenes(a9)
# prime_number=[]
# for i in range(2,a9):
#     if prime[i]:
#         prime_number.append(i)
def reverse_bisect_right(a, x, lo=0, hi=None):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x > a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x >= a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo

def get_list():
    return list(map(int, input().split()))

def get_str_list_in_int():
    return [int(i) for i in list(input())]

def get_str_list():
    return list(input())

def get_map():
    return map(int, input().split())

def input_int():
    return int(input())

def matrix(a, b):
    return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
    return b, a

def find_gcd(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a, l[i])
    return a;

def is_prime(n):
    sqrta = int(sqrt(n))
    for i in range(2, sqrta + 1):
        if n % i == 0:
            return 0;
    return 1;

def prime_factors(n):
    while n % 2 == 0:
        return [2] + prime_factors(n // 2)
    sqrta = int(sqrt(n))

    for i in range(3, sqrta + 1, 2):
        if n % i == 0:
            return [i] + prime_factors(n // i)

    return [n]

def p(a):
    if type(a) == str:
        print(a + "\n")
    else:
        print(str(a) + "\n")

def ps(a):
    if type(a) == str:
        print(a)
    else:
        print(str(a))

def kth_no_not_div_by_n(n, k):
    return k + (k - 1) // (n - 1)

def forward_array(l):
    n = len(l)
    stack = []
    forward = [0] * n
    for i in range(len(l) - 1, -1, -1):
        while len(stack) and l[stack[-1]] < l[i]:
            stack.pop()
        if len(stack) == 0:
            forward[i] = len(l);
        else:
            forward[i] = stack[-1]
        stack.append(i)
    return forward;

def backward_array(l):
    n = len(l)
    stack = []
    backward = [0] * n
    for i in range(len(l)):
        while len(stack) and l[stack[-1]] < l[i]:
            stack.pop()
        if len(stack) == 0:
            backward[i] = -1;
        else:
            backward[i] = stack[-1]
        stack.append(i)
    return backward

def char(a):
    return chr(a + 97)

def get_length(a):
    return 1 + int(log10(a))

nc = "NO"
yc = "YES"
ns = "No"
ys = "Yes"

# import math as mt
# MAXN=10**7
# spf = [0 for i in range(MAXN)]
# def sieve():
#     spf[1] = 1
#     for i in range(2, MAXN):
#         # marking smallest prime factor
#         # for every number to be itself.
#         spf[i] = i
#
#         # separately marking spf for
#     # every even number as 2
#     for i in range(4, MAXN, 2):
#         spf[i] = 2
#
#     for i in range(3, mt.ceil(mt.sqrt(MAXN))):
#
#         # checking if i is prime
#         if (spf[i] == i):
#
#             # marking SPF for all numbers
#             # divisible by i
#             for j in range(i * i, MAXN, i):
#
#                 # marking spf[j] if it is
#                 # not previously marked
#                 if (spf[j] == j):
#                     spf[j] = i
# def getFactorization(x):
#     ret = list()
#     while (x != 1):
#         ret.append(spf[x])
#         x = x // spf[x]
#
#     return ret
# sieve()

# if(os.path.exists('input.txt')):
#     sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")

# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# input=stdin.readline
# print=stdout.write
def issq(n):
    sqrta=int(n**0.5)
    return sqrta**2==n;
for i in range(int(input())):
    n,k=get_map()
    print(pow(n,k,mod))
print(1)


for _ in range(int(input())):
    n,k = map(int,input().split())
    a = n**k
    if n==1:
        a = 0
    a = a%((10**9)+7)
    print(a)


for _ in range(int(input())):
    m,k = map(int,input().split())
    print(m**k)


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


"""
    こんにちは。これはクシャルです

    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers

    I prefer Python language over the C++ language :p :D

    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    k,n = invr()
    print(pow(n,k,1000000007))

################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################

def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    t = inp()
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()

#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))

#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def factorial(n,m = 1000000007):
    q = 1
    for i in range(n):
        q = (q * (i + 1)) % m
    return(q)

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m):
        for j in range(n):
            b[i][j] = a[j][i]
    return(b)

def power_two(x):
    return (x and (not(x & (x - 1))))

def ceil(a, b):
    return -(-a // b)

def seive(n):
    a = [1]
    prime = [True for i in range(n + 1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p ** 2,n + 1,p):
                prime[i] = False
        p = p + 1
    for p in range(2,n + 1):
        if prime[p]:
            a.append(p)
    return(a)

def ncr(n,r):
    return(math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))

def npr(n,r):
    return(math.factorial(n) // math.factorial(n - r))

#-----------------------------------------------------------------------#

ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()


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


for _ in range(int(input())):
    n,k=map(int,input().split())
    print(n**k)


for _ in range(int(input())):
    a = list(map(int,input().strip().split()))
    h=a[0]
    m=a[1]
    print(h**m)


for _ in range(int(input())):
 a,b=map(int,input().split(' '))
 ans=1;
 mod=10**9+7
 for j in range(1,b):
  ans=(ans*a)%mod
 print(ans)


# region fastio
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

def intArr():
    return map(int, input().split())

def In():
    return int(input())

def func(n,k):
    mod=int(1e9)+7
    if k==1:
        return (n-1)%mod
    ans= ((1 << k) - 1) * (n - 1)
    ans=max(ans, ((1 << k) - 2) * (n - 1) + 1)
    return ans%mod

def main():
    for _ in range(In()):
        n,k=intArr()
        print(func(n,k))
    return

if __name__ == '__main__':
    main()


t = int(input())
while t>0:
    m = 1e9+7
    n, k = map(int, input().split(" "))
    num_elements = n
    for z in range(k):
        if z>0:
            num_elements *= n
    print(int(num_elements%m))

    t-=1


for _ in range(int(input())):
    a=list(map(int,input().split()))
    print(a[0]**a[1])


def modexp(a,b,mod):
    if b==0:
        return 1
    elif b%2==0:
        x=modexp(a%mod,b//2,mod)%mod
        return (x*x)%mod
    else:
        return ((a%mod)*(modexp(a%mod,b-1,mod)%mod))

t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    mod=10**9+7
    print(modexp(n,k,mod))


def f(n):
    ans=1
    for i in range(2,n+1):
        ans=(ans*i)%1000000007
    return ans
t=int(input())
for q in range(t):
    n,k=map(int,input().split())
    if n==1:
        print(0)
    else:
        print((n+(2**k-2)*f(n-1))%1000000007)


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


def proB(n,k):
    mod=1e9+7
    ans=1
    while(k):
        ans=ans*n
        k-=1
    return int(ans%mod)
t=int(input())
for i in range(t):
    n,k=list(map(int,input().split()))
    print(proB(n,k))


t=int(input())
for _ in range(t):
    n,k=map(int,input().split())
    m=n-1
    n=2
    p=1000000000+7
    result=1
    while m>0:
        if m%2==0:
            m //=2
            n =n*n %p
        else:
            result = result *n %p
            m -=1
    print(result)
    result =((result-1)*(k-1)*k +k)%p
    print(result)


from sys import stdin, stdout
from collections import *
from math import gcd, ceil, floor

def st():
    return list(stdin.readline().strip())

def li():
    return list(map(int, stdin.readline().split()))

def mp():
    return map(int, stdin.readline().split())

def inp():
    return int(stdin.readline())

def pr(n):
    return stdout.write(str(n) + "\n")

mod = 1000000007
INF = float('inf')
Y = "YES"
N = "NO"

def solve():
    # solve here
    n, k = mp()
    # AND of all numbers should be 0 & sum shd be largest
    # Hence, every bit should exaclty contain one zero
    # So, 0 1 1 1...
    #     1 0 1 1...
    #     1 1 0 1...
    # when we have k bits each has n choices to be zero (2^k-1 number has k bits)
    # n * n * n * n ... (k times) = n ^ k
    return pow(n, k, 10**9 + 7)

for test in range(int(input())):
    solve()


import math
t = int(input())
q = 0
while q<t:
    ls = input().split()
    n = int(ls[0])
    k = int(ls[1])
    i = 1
    N = n
    mod = 1e9+7
    while i<k:
        n=(n*N)
        i=i+1
    print(int(n%mod))
    q=q+1


for _ in range(int(input())):
    n,k = map(int,input().split())
    #l = list()
    print(n**k % 10000007)


import math
def isPrime(num):
    if num % 2 == 0:
        return False
    if num <= 3:
        return True
    a = int(math.sqrt(num)) + 1
    for x in range(3, a, 2):
        if num % x == 0:
            return False

    return True
def solve(num):

    if isPrime(num):
        return [x for x in range(1, num - 1)]
    out = [1]
    factors = []
    for x in range(2, num):
        if not num % x == 0:
            out.append(x)
        else:
            factors.append(x)

    newout = []
    test = 1
    for x in out:
        factor = False
        for y in factors:
            if x % y == 0:
                factor = True
                break
        if not factor:
            test *= x
            newout.append(x)

    out = newout
    lose = test % num

    while lose != 1:
        test = 1
        newout = []
        for x in out:
            if not x % lose == 0:
                newout.append(x)
                test *= x

        lose = test % num
        out = newout
    return out

if __name__ == "__main__":
    num = int(input())
    out = solve(num)
    print(len(out))
    print(' '.join(str(x) for x in out))


MOD = 10 ** 9 + 7
MAXN = 10 ** 5 + 123
MAXK = 22

fact = [1]
inv = [1]

s = [[ 0 for i in range(MAXK)] for j in range(MAXK)]
s[0][0] = 1

for n in range(1, MAXK):
  for k in range(1, n + 1):
    s[n][k] = (s[n - 1][k - 1] + k * s[n - 1][k]) % MOD

for i in range(1, MAXN):
    fact.append(fact[-1] * i % MOD)
    inv.append(pow(fact[-1], MOD - 2, MOD))

for _ in range(int(input())):
    n, k = map(int, input().split())

    ans = 0

    for parts in range(1, k + 1):
      mult = s[k][parts]

      cur = fact[n] * inv[n - parts] * mult

      ans = (ans + cur) % MOD

    print(ans)


from sys import stdin, stdout, setrecursionlimit
from collections import defaultdict as dd
from collections import deque
import math
# setrecursionlimit(int(1e7))
input = stdin.readline
flush = stdout.flush

def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p)) % p

prime = int(1e9+7)

tc = 1
tc = int(input())
for _ in range(tc):
    n, k = map(int, input().split())
    if n == 0:
        print(0)
    elif n == 1:
        print(1)
    else:
        ans = (pow(2, k, prime) - 2) % prime
        ans = (ans * ((n * (n-1)) // 2) + n) % prime
        print(ans)


MOD = 10 ** 9 + 7

def solve(N, K):
    if N == 1:
        return 0
    ans = (N ** K)
    return ans % MOD

T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    print(solve(N, K))


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


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
for _ in range(int(input())):
  n, k = map(int, input().split())
  if n == 1:
    print(0)
    continue
  print(pow(n, k, mod))


# 1&even = 0
# 0&any = 0

import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
for _ in range(int(inpu())) :
    n, k = map(int, inpu().split())
    # ans = 0
    # ans += (2**(k-1))*(n-1)
    # ans += (2**(k-1))*(2**k)*(n-1)
    prin(str((n**2)%(10**9+7)) + '\n')


#import io,os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

M = 998244353

MAXNUM = 260
factor = [1]*(MAXNUM+2)
factor[-1]=0
storecomb = {}

pows = [[1] for _ in range(250+1)]

for p in range(1,250+1):
    for _ in range(40000):
        pows[p].append((pows[p][-1]*p)%M )

#print(pows)

for i in range(1,MAXNUM+1):
    factor[i] = (factor[i-1]*i)%M

def fastfrac(a,b):
    numb = pow(b,M-2,M)
    return ((a%M)*(numb%M))%M

def comb(n,k):
#    print "*",n,k
    if n<k: return 0
    if n==k: return 1
    if (n,k) in storecomb:  return storecomb[(n,k)]

    num1 = factor[n]
    num2 = factor[k]
    num3 = factor[n-k]
    num = (num2*num3)%M
    output = fastfrac(num1,num)
    storecomb[(n,k)] = output
    return output

def main(t):

    n,k = map(int,input().split())

    dp = [[0 for q in range(k+1)] for p in range(n+1)]

    for j in range(1,k+1):
        dp[2][j] = 1

    for i in range(3,n+1):
        for j in range(1,k+1):
            dp[i][j] = pow(k-j+1,(i-1)*(i-2)//2,M)

    for i in range(3,n+1):

        for same in range(1,i-1):

            part1 = 0
            for j in range(2,k+1):

                part1 += dp[i-same][j-1]
           #     part2 = ( pow(k-j+1,same*(i-1-same)+same*(same-1)//2,M) * comb(i-1,same) ) %M
                part2 = pows[k-j+1][same*(i-1-same)+same*(same-1)//2] * comb(i-1,same) % M

                dp[i][j] += (part1*part2)%M

                dp[i][j] %= M

#    print(dp)

#    print(dp[n])
    print(sum(dp[n])%M)

T = 1 #int(input())
t = 1
while t<=T:
    main(t)
    t += 1


M = 998244353

MAXNUM = 260
factor = [1]*(MAXNUM+2)
factor[-1]=0
storecomb = {}

for i in range(1,MAXNUM+1):
    factor[i] = (factor[i-1]*i)%M

def fastfrac(a,b):
    numb = pow(b,M-2,M)
    return ((a%M)*(numb%M))%M

def comb(n,k):
#    print "*",n,k
    if n<k: return 0
    if n==k: return 1
    if (n,k) in storecomb:  return storecomb[(n,k)]

    num1 = factor[n]
    num2 = factor[k]
    num3 = factor[n-k]
    num = (num2*num3)%M
    output = fastfrac(num1,num)
    storecomb[(n,k)] = output
    return output

dic = {}

def getpow(i,j,M):
    if (i,j) in dic: return dic[(i,j)]
    else:
        dic[(i,j)] = pow(i,j,M)
        return dic[(i,j)]

def main(t):

    n,k = map(int,input().split())

    dp = [[0 for q in range(k+1)] for p in range(n+1)]

    for j in range(1,k+1):
        dp[2][j] = 1
        dp[1][j] = 1

    for i in range(3,n+1):
        for j in range(1,k+1):
            dp[i][j] = getpow(k-j+1,(i-1)*(i-2)//2,M)

    for i in range(3,n+1):

        for same in range(1,i-1):

            part1 = 0
            for j in range(2,k+1):

                part1 = (part1 + dp[i-same][j-1])%M
                part2 = ( getpow(k-j+1,same*(i-1-same)+same*(same-1)//2,M) * comb(i-1,same) ) %M

                dp[i][j] += (part1*part2)%M

                dp[i][j] %= M

#    print(dp)

#    print(dp[n])
    print(sum(dp[n])%M)

T = 1 #int(input())
t = 1
while t<=T:
    main(t)
    t += 1