// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ll
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static int findIndex(long arr[], long t)
    {

        // if array is Null
        if (arr == null) {
            return -1;
        }

        // find length of array
        int len = arr.length;
        int i = 0;

        // traverse in the array
        while (i < len) {

            // if the i-th element is t
            // then return the index
            if (arr[i] == t) {
                return i;
            }
            else {
                i = i + 1;
            }
        }
        return -1;
    }

    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    static int lcm(int a, int b)
    {
        return (a / gcd(a, b)) * b;
    }
    public static int[] swap(int a[], int left, int right)
    {

        // Swap the data
        int temp = a[left];
        a[left] = a[right];
        a[right] = temp;

        // Return the updated array
        return a;
    }
    public static int[] reverse(int a[], int left, int right)
    {

        // Reverse the sub-array
        while (left < right) {
            int temp = a[left];
            a[left++] = a[right];
            a[right--] = temp;
        }

        // Return the updated array
        return a;
    }
    public static int[] findNextPermutation(int a[])
    {
        int last = a.length - 2;

        // find the longest non-increasing suffix
        // and find the pivot
        while (last >= 0) {
            if (a[last] < a[last + 1]) {
                break;
            }
            last--;
        }

        // If there is no increasing pair
        // there is no higher order permutation
        if (last < 0)
            return a;

        int nextGreater = a.length - 1;

        // Find the rightmost successor to the pivot
        for (int i = a.length - 1; i > last; i--) {
            if (a[i] > a[last]) {
                nextGreater = i;
                break;
            }
        }

        // Swap the successor and the pivot
        a = swap(a, nextGreater, last);

        // Reverse the suffix
        a = reverse(a, last + 1, a.length - 1);

        // Return true as the next_permutation is done
        return a;
    }
    static int factorial(int n)
  {
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
  }
    public static void main(String[] args)
    {
            FastReader d=new FastReader();
            int t,i,j,c,z,k,l,n;
            int mod = (int) 1e9 + 7;

            int Inf=Integer.MAX_VALUE;
            int negInf=Integer.MIN_VALUE;
        t=d.nextInt();
        //t=1;
        //String s;
        //char ch,ch1,ch2,ch3;
        while(t-->0)
        {
            z=c=0;
            long nn=d.nextLong();
            int kk=d.nextInt();
            //int a[]=new int[n];
            //for(i=0;i<n;i++)
            //a[i]=d.nextInt();
            long xx=1l;
            for(i=1;i<=kk;i++)
            xx*=nn%mod;
            System.out.println(xx);
            //s=d.nextLine();//dont need extra d.nextLine()
        }
    }
}


// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ll
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static int findIndex(long arr[], long t)
    {

        // if array is Null
        if (arr == null) {
            return -1;
        }

        // find length of array
        int len = arr.length;
        int i = 0;

        // traverse in the array
        while (i < len) {

            // if the i-th element is t
            // then return the index
            if (arr[i] == t) {
                return i;
            }
            else {
                i = i + 1;
            }
        }
        return -1;
    }

    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    static int lcm(int a, int b)
    {
        return (a / gcd(a, b)) * b;
    }
    public static int[] swap(int a[], int left, int right)
    {

        // Swap the data
        int temp = a[left];
        a[left] = a[right];
        a[right] = temp;

        // Return the updated array
        return a;
    }
    public static int[] reverse(int a[], int left, int right)
    {

        // Reverse the sub-array
        while (left < right) {
            int temp = a[left];
            a[left++] = a[right];
            a[right--] = temp;
        }

        // Return the updated array
        return a;
    }
    public static int[] findNextPermutation(int a[])
    {
        int last = a.length - 2;

        // find the longest non-increasing suffix
        // and find the pivot
        while (last >= 0) {
            if (a[last] < a[last + 1]) {
                break;
            }
            last--;
        }

        // If there is no increasing pair
        // there is no higher order permutation
        if (last < 0)
            return a;

        int nextGreater = a.length - 1;

        // Find the rightmost successor to the pivot
        for (int i = a.length - 1; i > last; i--) {
            if (a[i] > a[last]) {
                nextGreater = i;
                break;
            }
        }

        // Swap the successor and the pivot
        a = swap(a, nextGreater, last);

        // Reverse the suffix
        a = reverse(a, last + 1, a.length - 1);

        // Return true as the next_permutation is done
        return a;
    }
    static int factorial(int n)
  {
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
  }
    public static void main(String[] args)
    {
            FastReader d=new FastReader();
            int t,i,j,c,z,k,l,n;
            int mod = (int) 1e9 + 7;

            int Inf=Integer.MAX_VALUE;
            int negInf=Integer.MIN_VALUE;
        t=d.nextInt();
        //t=1;
        //String s;
        //char ch,ch1,ch2,ch3;
        while(t-->0)
        {
            z=c=0;
            long nn=d.nextLong();
            long kk=d.nextLong();
            //int a[]=new int[n];
            //for(i=0;i<n;i++)
            //a[i]=d.nextInt();
            long xx;
            for(i=1;i<=k;i++)
            xx*=n%mod;
            System.out.println(xx);
            //s=d.nextLine();//dont need extra d.nextLine()
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
//_________________________________________________________________
public class Main {

    public static void main(String[] args) throws IOException {

//        File file = new File("input.txt");
        FastScanner sc = new FastScanner();
//                Scanner sc= new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t=sc.nextInt();
        outer:while (t-->=1){
            int n=sc.nextInt(),k=sc.nextInt();
            int max=Math.max(n,k);
            int min=Math.min(n,k);
            long ans=(long)Math.pow(n,k);
//            System.out.println((ans%mod+mod)%mod);
            long mode=(long)(1e9+7);
//            ans%=mode;
            System.out.println(ans%mode);
        }

        out.flush();
    }
    //------------------------------------if-------------------------------------------------------------------------------------------------------------------------------------------------
    //sieve
    static void primeSieve(int a[]){
        //mark all odd number as prime
        for (int i=3;i<=1000000;i+=2){
            a[i]=1;
        }
        for (long i=3;i<=1000000;i+=2){
            //if the number is marked then it is prime
            if (a[(int) i]==1){
                //mark all muliple of the number as not prime
                for (long j=i*i;j<=1000000;j+=i){
                    a[(int)j]=0;
                }
            }
        }
        a[2]=1;
        a[1]=a[0]=0;
    }
    static void sort(int[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a) l.add(i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }
    static String sortString(String s) {
        char temp[] = s.toCharArray();
        Arrays.sort(temp);
        return new String(temp);
    }
    static class Pair implements Comparable<Pair> {
        int a;
        int b;

        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
        //        to sort first part
//        public int compareTo(Pair other) {
//            if (this.a == other.a) return other.b > this.b ? -1 : 1;
//            else if (this.a > other.a) return 1;
//            else return -1;
//        }
//        public int compareTo(Pair other) {
//            if (this.b == other.b) return 0;
//            if (this.b < other.b) return 1;
//            else return -1;
//        }
        //sort on the basis of first part only
        public int compareTo(Pair other) {
            if (this.a == other.a) return 0;
            else if (this.a > other.a) return 1;
            else return -1;
        }

    }
    static int[] frequency(String s){
        int fre[]= new int[26];
        for (int i=0;i<s.length();i++){
            fre[s.charAt(i)-'a']++;
        }
        return fre;
    }
    static int mod =(int)(1e9+7);
    static long mod(long x) {
        return ((x % mod + mod) % mod);
    }
    static long add(long x, long y) {
        return mod(mod(x) + mod(y));
    }
    static long mul(long x, long y) {
        return mod(mod(x) * mod(y));
    }
    static int[] find(int n, int start, int diff) {
        int a[] = new int[n];
        a[0] = start;
        for (int i = 1; i < n; i++) a[i] = a[i - 1] + diff;
        return a;
    }
    static void swap(int a, int b) {
        int c = a;
        a = b;
        b = c;
    }
    static void printArray(int a[]) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }
    static boolean sorted(int a[]) {
        int n = a.length;
        boolean flag = true;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] > a[i + 1]) flag = false;
        }
        if (flag) return true;
        else return false;
    }
    public static int findlog(long n) {
        if (n == 0)
            return 0;

        if (n == 1)
            return 0;
        if (n == 2)
            return 1;
        double num = Math.log(n);
        double den = Math.log(2);
        if (den == 0)
            return 0;
        return (int) (num / den);
    }
    public static long gcd(long a, long b) {
        if (b % a == 0)
            return a;
        return gcd(b % a, a);
    }
    public static int gcdInt(int a, int b) {

        if (b % a == 0)
            return a;

        return gcdInt(b % a, a);

    }
    static void sortReverse(int[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a) l.add(i);
        //        Collections.sort.(l);
        Collections.sort(l, Collections.reverseOrder());
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }
    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long[] readArrayLong(long n) {
            long[] a = new long[(int) n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


 import java.util.*;
import java.io.*;
public class B{
    static final int MOD=1000000007;
    public static FastReader sc=new FastReader();
     public static PrintWriter  out = new PrintWriter(System.out);
     static int gcd(int a,int b){
         if(b==0)return a;
         return gcd(b,a%b);
     }
     static long pow(int n,int k){
         if(k==0)return 1;
         if(k%2==0){
            long v=pow(n,k/2)%MOD;
            return (v*v)%MOD;
         }
         else return ((n%MOD)*(pow(n,k-1)%MOD));
     }
    public static void taskSolver(){
       int n=sc.nextInt();
       int k=sc.nextInt();long ans=1;
       out.println(pow(n,k));
    }

      public static void main(String args[]) throws java.lang.Exception{
            int t=sc.nextInt();
            while(t-->0)
           taskSolver();
           out.close();
       }
      static class Pair{
          int x;int y;
          Pair(int x,int y){
              this.x=x;this.y=y;
          }
      }
    static  class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
   }


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Main
{
	private static Scanner in=new Scanner(System.in);

	public static void main(String[] args)
	{
		int n=in.nextInt(),k=in.nextInt();
		System.out.println(qpow(n,k,Mod));
	}

	public static long Mod=(long) (10e9+7);
	public static long qpow(long a,long b,long Mod)
	{
		long res=1;
		while((b>>=1)>0)
		{
			if((b&1)==1)
			{
				res=(res*a)%Mod;
			}
			a=(a*a)%Mod;
		}
		return res;
	}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static int MAX_SIZE = 1000001 ;
    public static Vector<Boolean> isprime = new Vector<Boolean>(MAX_SIZE);
    public static Vector<Integer> primes = new Vector<Integer>(MAX_SIZE) ;
    public static Vector<Integer> SPF = new Vector<Integer>(MAX_SIZE);

    public static void sieve (int n ) {
        isprime.set(0,false);
        isprime.set(1, false) ;
        for (int i  = 2 ; i < n ;  i ++ )  {
            if (isprime.get(i)) {
                primes.add(i);
                SPF.add(i);
            }
            for (int j = 2 ; i*primes.get(j) <= n  ; j +=i ) {

            }

        }

    }

    public static ArrayList<Stack<Integer>> as = new ArrayList<Stack<Integer>>();

    public static int k ;
    public static Stack<Integer>q=new Stack<Integer>();

    public static void  permutation (int [] a,int n , int mask, int taken) {

        if (taken == n  ) {

            arr = q.toArray();
            backtrack((int)arr[0],0, 1);
            return ;

        }
        else {
            for(int i = 0 ; i < n ; i++  ) {
                if ((mask &(1 << i)) == 0 ) {
                    q.add((int)a[i]);

                    permutation(a,n, mask | (1 <<i) , taken+1);
                    q.pop();
                }
            }
        }

    }

    public static boolean gsd(long x , int y) {
        for(int i = 2 ; i <= Math.min(y, x) ; i ++ ) {
            if (x%i == 0 && y%i == 0 ) return true;
        }
        return false;
    }
    public static int s(long x) {
        int sum = 0 ;
        do {
            sum += x%10 ;
            x /= 10;
        }while(x >0 );
        return sum;
    }
    public static int right(String s) {
        int c = 0 ;
        for(int i = s.length()-1 ; i>=0; i -- ) {
            if(s.charAt(i) == 'a') c++ ;
            else break;
        }
        return c;
    }
    public static int left(String s) {
        int c = 0 ;
        for(int i = 0 ; i<s.length(); i ++ ) {
            if(s.charAt(i) == 'a') c++ ;
            else break;
        }
        return c;
    }
    public static boolean onlyas (String s) {
        for (int i = 0 ; i < s.length() ; i ++ ) {
            if (s.charAt(i) != 'a') return false ;
        }return true;
    }
    public static String convert(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0 ; i < s.length() ; i ++ ) {
            if (s.charAt(i) == '1') sb.append("0");
            else sb.append("1");
        }
        return sb.toString();
    }
    public static int check (String s) {
//		boolean flag = false ;
        for (int i = 0 ; i < s.length() ; i ++) {
            if (Character.isDigit(s.charAt(i)) ) {
                for (int j = i ; j <s.length() ; j ++ ) {
                    if (!Character.isDigit(s.charAt(j)))return 0 ;
                }
                return 1 ;
            }

        }
        return 1;
    }
    public static String s26 (int n) {
        StringBuilder st = new StringBuilder();
        while (n >0) {
            int x = n%26 ;
            n /= 26 ;
            if (x-1 <0 ) {
                x = 26;n-- ;
            }
            st.insert(0, letters[x-1]);
        }
        return st.toString();
    }

    public static int sum = 0 ;
    public static int tokens = 0 ;
    public static Object arr [] = new Integer [5];
    public static boolean flag = false ;
    public static void backtrack (int ss , int idx , int tks) {

        if (tks == 5 )  {
//			System.out.println(ss + " ");
            if (ss  == 23 ) {//System.out.print(ss+" " );
                flag = true ; return ;
            }
        }else {
            backtrack(ss+ (int)arr[idx+1], idx+1, tks+1);
            backtrack(ss*(int)arr[idx+1], idx+1, tks+1);
            backtrack(ss-(int)arr[idx+1], idx+1, tks+1);

        }

    }
    public static int length (int n) {
        int l = 0 ;
        while (n > 0 ) {
            l ++ ;
            n /=10 ;
        }
        return l ;
    }
    public static int GSD (int x , int y  )  {
        for (int i = x ; i >0 ; i -- ) {
            if (x% i== 0 && y % i==  0 ) return i;
        }
        return 1 ;
    }

    public static char [] letters = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O'
            ,'P','Q','R','S','T','U','V','W','X','Y', 'Z'};
    public static void main(String[] args)  throws IOException, InterruptedException{
        PrintWriter pw = new PrintWriter(System.out);
        Scanner sc = new Scanner (System.in);

        int t = sc.nextInt();
        while (t-- >  0 ) {
            long n = sc.nextLong() ;
            int k = sc.nextInt();
            for (int i = 0 ; i < k ; i ++ ) {
                n *= n ;
                 n%= 1000000007 ;
            }
           pw.println(n);

        }
        pw.close ();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }

}

/*
while (true) {

		int []a = new int [5];

		for (int i = 0 ; i < 5 ; i ++ ) {
			arr[i]= sc.nextInt();
			a[i]= (int)arr[i];;
		}
		if (a[0] == 0) break ;
		permutation(a, 5, 0, 0);

		pw.println(flag ? "Possible":"Impossible");
		}

*/


import java.util.*;
public class And0 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t-->0){
            int n=sc.nextInt();
            int k=sc.nextInt();
            long nas=1;
            long mod=100000007;
            for (int i = 0; i < k; i++) {
nas=  ((nas*n)%mod);
            }
            System.out.println(nas);
        }
    }
}


import java.io.*;
import java.lang.*;
import java.util.*;
public class b
{
static class FastScanner {
InputStreamReader is;
BufferedReader br;
StringTokenizer st;
public FastScanner() {
is = new InputStreamReader(System.in);
br = new BufferedReader(is);
}
String next() throws Exception {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws Exception {
return Integer.parseInt(next());
}
long nextLong() throws Exception {
return Long.parseLong(next());
}
int[] readArray(int num) throws Exception {
int arr[]=new int[num];
for(int i=0;i<num;i++)
arr[i]=nextInt();
return arr;
}
String nextLine() throws Exception {
return br.readLine();
}
}
 public static boolean power_of_two(int a)
{
  if((a&(a-1))==0)
{
 return true;
}
return false;
}
public static void main(String args[]) throws java.lang.Exception
{
FastScanner sc=new FastScanner();

int t=sc.nextInt();
while(t-->0)
{
    int n=sc.nextInt();
    int k=sc.nextInt();
    long ans=(long)Math.pow(n,k)%1000000007;
System.out.println(ans);
}
}
}


// Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Q2 {
	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException
		{
			din = new DataInputStream(
				new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException
		{
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n') {
					if (cnt != 0) {
						break;
					}
					else {
						continue;
					}
				}
				buf[cnt++] = (byte)c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ') {
				c = read();
			}
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0,
								BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
		}
	}

	public static final long max=(long) (Math.pow(10,9)+7);
	public static void main(String[] args)
		throws IOException
	{
		Reader s = new Reader();
		int t=s.nextInt();
		while(t-->0) {
			long n=s.nextInt();
			int k=s.nextInt();
			n=((n*(n-1))%max);
			long ans=(long) ((Math.pow(2,k-1)*n)%max);
			System.out.println(ans);
		}
	}
}


import java.util.Scanner;

public class And_0_sum_Big {

	public static void main(String[] args) {

	 Scanner sc=new Scanner(System.in);
	 int t=sc.nextInt();
	 while(t-- > 0 ) {
		 int n=sc.nextInt();
		 int k=sc.nextInt();
		 System.out.println(pow(n,k)%(1000000007));
	 }

	}

	private static long  pow(int n, int k) {
		 if(k==0) return 1;
		 if(k==1) return n;
		  long temp=pow(n,k>>1);
		 long res= ((temp*temp)%(1000000007));
		 if((k&1)==1) return res*=n;

		return res%1000000007;
	}

}


import java.io.*;
import java.util.*;

public class AND0SumBig {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
// System.in and System.out are input and output streams, respectively.
		InputStream inputStream = System.in;

		InputReader in = new InputReader(inputStream);
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
		int t = in.nextInt();
		int mod = 1000000007;
		while (t-- != 0) {
			int n = in.nextInt();
			int k = in.nextInt();
			long ans = n;
			while (k-- != 0) {
				ans *= n;
				ans %= mod;
			}
			out.write(ans + "\n");
		}
		out.close();
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] readArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}
	}

}


import java.util.*;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuffer out=new StringBuffer();

		int t=in.nextInt();

		outer:
		while(t--!=0) {

			int n=in.nextInt(),
				k=in.nextInt();

			long ans=1, mod=1_000_000_007;
			for(int i=0; i<20; i++)
				ans=(ans*n)%mod;

			out.append(ans+"\n");
		}

		System.out.println(out);
	}
}


import java.util.Scanner;
public class Main{
    public static void main(String[] args)
    {
    	Scanner cin = new Scanner(System.in);
    	int t=cin.nextInt(),i;
    	for(i=0;i<t;i++)
    	{
    		long n=cin.nextLong(),k=cin.nextLong();
    		double num=Math.pow(n,k)%1000000007;
    		System.out.println(String.format("%.0f", num));;
    	}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class A{
   static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        StringBuilder sb=new StringBuilder();
        int m=1000000007;
        while(t-->0){
          int n=sc.nextInt();
          int k=sc.nextInt();
          int p=(int)Math.pow(2,k);
          p=p-1;
          p=p/2;
          long ans=(long)((long)n%m*(long)(n-1)%m)%m;
          ans=(ans%m*(long)p%m)%m;
          ans=(ans%m+(long)n%m)%m;
          System.out.println(ans%m);
        }
   }
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
    static long mod=1000000007;
    static FastReader sc=new FastReader();
    static long power(long x, long y)
    {
    long res = 1;     // Initialize result
    while (y > 0)
    {

        // If y is odd, multiply x with result
        if ((y & 1) != 0)
            res = res * x;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x%mod * x%mod)%mod;  // Change x to x^2
    }
    return res;
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		int t=sc.nextInt();
		for(int y=0;y<t;++y)
		{
		    long n=sc.nextLong();
		    long k=sc.nextLong();
		    System.out.println(power(n,k)%mod);

		}
    }

	static void printintarray(int[] arr)
{
	int n=arr.length;
	for(int i=0;i<n;++i)
	{
		System.out.print(arr[i]+" ");
	}
	System.out.println();
}
	static void printlongarray(long[] arr)
{
	int n=arr.length;
	for(int i=0;i<n;++i)
	{
		System.out.print(arr[i]+" ");
	}
	System.out.println();
}

	static int[] arrayintinput(int n)
	{
	    int arr[]=new int[n];
	    for(int i=0;i<n;++i)
	    {
	        arr[i]=sc.nextInt();
	    }
	    return arr;
	}
	static long[] arraylonginput(int n)
	{
	    long arr[]=new long[n];
	    for(int i=0;i<n;++i)
	    {
	        arr[i]=sc.nextLong();
	    }
	    return arr;
	}
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(
                new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        long nextLong() { return Long.parseLong(next()); }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}
//  System.out.println("Case #"+(y+1)+": "+ans);


import java.util.*;
import java.io.*;
import java.lang.Math;

public class A {

	static int INF = -2_000_000_000;
	static long MOD = 1_000_000_007;
	static int MAX_PRIME = 1_000_000_000;
	public static void main(String args[]) {
		FastScanner fs=new FastScanner();
		int t = fs.nextInt();
		System.out.println(modPow(3, 3));
		outer: for(int tt=0; tt < t; tt++) {
			int n=fs.nextInt();
			int k =fs.nextInt();

			System.out.println(modPow(n, k));
		}
	}
	static long modPow(long x, long y) {
		if(y == 0)
			return 1;

		long mid = modPow(x, y/2);
		if((y&1)==1) {
			return (((mid*mid)%MOD)*x)%MOD;
		} else {
			return (mid*mid)%MOD;
		}
	}

	static boolean perfectSquare(int x) {
		return (int)Math.sqrt(x) * (int)Math.sqrt(x) == x;
	}

	static class Pair implements Comparable<Pair>{
		long first, second;
		public Pair(long l, long i) {
			first=l;second=i;
		}
		public Pair() {
			first=0;second=0;
		}
		public int compareTo(Pair x) {
			if(this.first<x.first)
				return -1;
			if(this.first==x.first)
				return this.second<x.second?-1:(this.second==x.second?0:1);
			return 1;
		}
	}

	static class RangeMin {
		long logs[], st[][];
		// sparse table?
		int N, K;
		public RangeMin(int n) {
			N=n;
			K = (int)((double) (Math.log10((double)n) /(double) Math.log10((double)2) ));
			st = new long [N+2][K+2];
			logs = new long[N+2];
		}
		void init(ArrayList<Integer> A) {

			for(int i = 0; i < N; i++) {
				Arrays.fill(st[i], (long)1e18);
				st[i][0]=(long)A.get(i);
			}
			// NLOGN
			for(int j = 1; j <= K; j++) {
				for(int i = 0; i + (1<<j) <= N; i++) {
					st[i][j]=Math.min(st[i][j-1], st[i + (1 << (j-1))][j-1]);
				}
			}
			logs[1]=0;
			for(int i = 2; i <= N; i++) {
				logs[i]=logs[i/2]+1;
			}
		}
		void init(int [] A) {

			for(int i = 0; i < N; i++) {
				Arrays.fill(st[i], (long)1e18);
				st[i][0]=(long)A[i];
			}
			// NLOGN
			for(int j = 1; j <= K; j++) {
				for(int i = 0; i + (1<<j) <= N; i++) {
					st[i][j]=Math.min(st[i][j-1], st[i + (1 << (j-1))][j-1]);
				}
			}
			logs[1]=0;
			for(int i = 2; i <= N; i++) {
				logs[i]=logs[i/2]+1;
			}
		}

		long query(int L, int R) {
			int j = (int)logs[R-L+1];
			return Math.min(st[L][j], st[R - (1 << j) + 1][j]);
		}
	}

	static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int[] nextArray(int n) {
            int a[] = new int[n];
            for(int i =0; i < n; i++) a[i]=this.nextInt();
            return a;
        }
        public int max(int a[]) {
        	int mx = Integer.MIN_VALUE;
        	for(int i : a)
        		mx = Math.max(i, mx);
        	return mx;
        }
        public int count(int a[], int val) {
        	int ans =0;
        	for(int i : a)
        		ans += val == i ? 1 : 0;
        	return ans;
        }
        public int min(int a[]) {
        	int mn = Integer.MAX_VALUE;
        	for(int i : a)
        		mn = Math.min(i, mn);
        	return mn;
        }
        public void randomShuffleSort(int []a) {
			Random r = new Random();
            for(int i =0; i < (a.length)/2; i++) {
                int temp=a[i],p=r.nextInt(a.length);
                a[i]=a[p];
                a[p]=temp;
            }
            this.fine_sort(a);
        }
        public void fine_sort(int a[]) {
            ArrayList<Integer> A = new ArrayList<>();
            for(int i : a) A.add(i);
            Collections.sort(A);
            for(int i=0; i < a.length; i++) {
                a[i]=A.get(i);
            }
        }
    }

	static class SegmentTree {
    	int leftmost, rightmost;
    	SegmentTree lChild, rChild;
    	int sum;
    	long lz_val;

    	public SegmentTree(int l, int r, int a[]) {
    		leftmost = l;
    		rightmost = r;
    		lz_val=0;
    		if(l == r)
    			sum = a[l];
    		else {
    			int mid = (l + r) / 2;
    			lChild = new SegmentTree(l, mid, a);
    			rChild = new SegmentTree(mid+1, r, a);
    			update();
    		}
    	}
    	public void update() {
    		sum = lChild.sum + rChild.sum + (int)lChild.lz_val + (int)rChild.lz_val;
    	}
    	public void pointUpdate(int pos, int val) {
    		if(leftmost == rightmost) {
    			sum = val;
    		} else {
    			int mid = (leftmost + rightmost) / 2;
    			if(pos <= lChild.rightmost) lChild.pointUpdate(pos, val);
    			else rChild.pointUpdate(pos, val);
    			update();
    		}
    	}
    	public void rangeUpdate(int l, int r, int val) {
    		// first check if it's within the range
    		if(l <= leftmost && r >= rightmost) {
    			lz_val += val;
    		} else {
    			// its not within the range so lets update the left if we have to and update the right if we have to
    			if(lChild.rightmost >= l) lChild.rangeUpdate(l, r, val);
    			if(rChild.leftmost <= r) rChild.rangeUpdate(l, r, val);
    			update();
    		}
    	}
    	public long query(int l, int r) {
    		if(l > rightmost || r < leftmost) return 0;
    		else if(l <= leftmost && r >= rightmost) return sum + lz_val;

    		return (long) lChild.query(l, r) + (long) rChild.query(l, r);
    	}
    }
}


import java.util.*;
public class B {
	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int t =0;
		long mod = (long) 1e9 + 7;
		for(int tt = 0 ;tt <t ;tt++) {
			int n = sc.nextInt() , k = sc.nextInt();

			long ans = 1;
			for (int i = 0; i < k; i++) ans = (ans * n) % mod;
			System.out.println(ans);		}
	}
}


import java.util.Scanner;

public class sumobig {
    static long big_mod(long base, long power, long mod)
    {
        if(power==0)    return 1;
            //কোন কিছুর power 0 হলে তার মান 1 হয়ে যায়
        else if(power%2==1) //power বেজোড় হলে
        {
            long p1 = base % mod;
            long p2 = (big_mod(base,power-1,mod))%mod;
            return (p1*p2)%mod;
        }
        else if(power%2==0) //power জোড় হলে
        {
            long p1 = (big_mod(base,power/2,mod))%mod;
            return (p1*p1)%mod;
        }
        return 1;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long k = scanner.nextLong();
        System.out.println(big_mod(n,k ,1000000007));
    }
}


/*
 * akshaygupta26
 */
import java.io.*;
import java.util.*;
public class B
{
    public static void main(String[] args)
	{
		FastReader sc=new FastReader();
		StringBuffer ans=new StringBuffer();
		int test=sc.nextInt();
		while(test-->0)
		{
			int n=sc.nextInt();int bits=sc.nextInt();
			int mod = (int)(1e9+7);
			int xy= binexp(n,bits,mod);
			ans.append(xy+"\n");
		}
	    System.out.print(ans);
	}

    static int binexp(int a,int b,int mod) {
    	if(b == 0) return 1;
    	int temp =binexp(a,b/2,mod);
    	temp=(int)((temp*1l*(long)temp)%mod);
    	if(b%2 == 1) temp=(temp*a)%mod;
    	return temp;
    }

    static long _gcd(long a,long b) {
    	if(b == 0) return a;
    	return _gcd(b,a%b);
    }

    static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static void ruffleSort(long[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n);
			long temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

}


//------------------>>>>>>>>>>>>>>>> HI . HOW ARE YOU? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<------------------------------

import java.util.*;
import java.math.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

//---------------------------->>>>>>>>>>>>>>>>>>>>>> FK OFF <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-------------------

public class practice{
    static long[] count,count1,count2;
    static boolean[] prime;
    static int[] spf;
    static Node[] nodes,nodes1,nodes2;
    static long[] arr;
    static long[][] cost;
    static int[] arrInt,darrInt,farrInt;
    static long[][] dp;
    static char[] ch,ch1,ch2;
    static long[] darr,farr;
    static char[][] mat,mat1;
    static boolean[] vis;
    static long x,h;
    static long maxl,sum,total;
    static double dec;
    static long mx = (long)1e7;
    static long inf = (long)1e18;
    static String s,s1,s2,s3,s4;
    static long minl;
    static long mod = (long)1e9+7;
    // static int minl = -1;
    // static long n;
    static int n,n1,n2,q,r1,c1,r2,c2;
    static int arr_size = (int)2e5+10;
    static long a;
    static long b;
    static long c;
    static long d;
    static  int centroids;
    static long y,z;
    static int m;
    static int ans;
    static long k;
    static FastScanner sc;
    static String[] str,str1;
    static Set<Long> set,set1,set2;
    static SortedSet<Long> ss;
    static List<Long> list,list1,list2,list3;
    static PriorityQueue<Node> pq,pq1;
    static LinkedList<Node> ll,ll1,ll2;
    static Map<Integer,List<Node>> map;
    static Map<Integer,Integer> map2;
    static Map<Integer,Node> map1;
    static StringBuilder sb,sb1,sb2;
    static int index;
    static int[] dx = {0,-1,0,1,-1,1,-1,1};
    static int[] dy = {-1,0,1,0,-1,-1,1,1};

    static class Node{
        int first;
        long wt;
        Node(int f,long s){
            this.first = f;
            this.wt = s;
        }
    }

    // public static void solve(){

    //    FastScanner sc = new FastScanner();
    //    int t = sc.nextInt();
    //    // int t = 1;
    //    for(int tt = 1 ; tt <= t ; tt++){

    //        System.out.println("Case #"+tt+": "+cost);

    //    }

    // }

    //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<------------------------------

    //------------>>>>>NEVER GIVE UP <<<<<--------------------------------------------------------------

    public static void solve(){

//        System.out.println(mod(a*a));
        if(a == 1){
            sb.append("0\n");
        }
        else
            sb.append(power(a,b)+"\n");

    }

    //------------>>>>>NEVER GIVE UP <<<<<--------------------------------------------------------------

    //----------->>>>>>> SPEED UP SPEED UP . THIS IS SPEEDFORCES . SPEED UP SPEEEEEEEEEEEEEEEEEEEEEEEEEEDDDDDD <<<<<<<------------------

    public static void main(String[] args) {

        sc = new FastScanner();
        // Scanner sc = new Scanner(System.in);
        sb = new StringBuilder();
         int t = sc.nextInt();
//        int t = 1;
        while(t > 0){

            // k = sc.nextLong();
            // x = sc.nextLong();
            // y = sc.nextLong();
            // z = sc.nextLong();

             a = sc.nextLong();
             b = sc.nextLong();
//             c = sc.nextLong();
//             d = sc.nextLong();

//             x = sc.nextLong();
//             y = sc.nextLong();
//             z = sc.nextLong();
            // d = sc.nextLong();

//            n = sc.nextInt();

            // n1 = sc.nextInt();

//            m = sc.nextInt();
//             q = sc.nextInt();

            // a = sc.nextLong();
            // b = sc.nextLong();

//             k = sc.nextLong();

            // x = sc.nextLong();
            // d = sc.nextLong();

            // s = sc.next();

//            ch = sc.next().toCharArray();
            // ch1 = sc.next().toCharArray();

//             m = sc.nextInt();
            // n = 6;

//             arr = new long[n];
//             for(int i = 0 ; i < n ; i++){
//                 arr[i] = sc.nextLong();
//             }

            // arrInt = new int[n+1];
            // for(int i = 1 ; i <= n ; i++){
            //     arrInt[i] = sc.nextInt();
            // }

            // x = sc.nextLong();
            // y = sc.nextLong();
//             ch = sc.next().toCharArray();
//             m = n;
////             m = sc.nextInt();
//             darr = new long[m];
//             for(int i = 0 ; i < m ; i++){
//                 darr[i] = sc.nextLong();
//             }
            // k = sc.nextLong();
            // m = n;
            // darrInt = new int[n];
            // for(int i = 0 ; i < n ; i++){
            //     darrInt[i] = sc.nextInt();
            // }

            // farr = new long[m];
            // for(int i = 0 ; i < m ; i++){
            //     farr[i] = sc.nextLong();
            // }

            // farrInt = new int[m];
            // for(int i = 0; i < m ; i++){
            //     farrInt[i] = sc.nextInt();
            // }

            // m = n;
//            mat = new long[n][m];
//            for(int i = 0 ; i < n ; i++){
//                for(int j = 0 ; j < m ; j++){
//                    mat[i][j] = sc.nextLong();
//                }
//            }

//             m = n;
//             mat = new char[n][m];
//             for(int i = 0 ; i < n ; i++){
//                 String s = sc.next();
//                 for(int j = 0 ; j < m ; j++){
//                     mat[i][j] = s.charAt(j);
//                 }
//             }

            // str = new String[n];
            // for(int i = 0 ; i < n ; i++)
            //     str[i] = sc.next();

            // nodes = new Node[n];
            // for(int i = 0 ; i < n ;i++)
            //     nodes[i] = new Node(sc.nextInt(),i);

            solve();
            t -= 1;
        }
        System.out.print(sb);

    }

    public static int log(double n,double base){

        if(n == 0 || n == 1)
            return 0;

        if(n == base)
            return 1;

        double num = Math.log(n);
        double den = Math.log(base);

        if(den == 0)
            return 0;

        return (int)(num/den);
    }

    public static boolean isPrime(long n) {
        // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
                return false;

        return true;
    }

    public static void SpecialSieve(int MAXN)
    {
        spf = new int[MAXN];
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)

            // marking smallest prime factor for every
            // number to be itself.
            spf[i] = i;

        // separately marking spf for every even
        // number as 2
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {
            // checking if i is prime
            if (spf[i] == i)
            {
                // marking SPF for all numbers divisible by i
                for (int j=i*i; j<MAXN; j+=i)

                    // marking spf[j] if it is not
                    // previously marked
                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }

    public static ArrayList<Integer> getFactorization(int x)
    {
        ArrayList<Integer> ret = new ArrayList<Integer>();
        while (x != 1)
        {
            ret.add(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }

    public static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b)
    {
        return (b/gcd(b, a % b)) * a;
    }

    public static long mod_inverse(long a,long mod){
        long x1=1,x2=0;
        long p=mod,q,t;
        while(a%p!=0){
            q = a/p;
            t = x1-q*x2;
            x1=x2; x2=t;
            t=a%p;
            a=p; p=t;
        }
        return x2<0 ? x2+mod : x2;
    }

    public static void swapF(int[] curr,int l,int r){
        for(int i = l ; i < (r-l+1)/2 ; i++){
            swap(curr,i,r-i);
        }
    }

    public static void swap(int[] curr,int i,int j){
        int temp = curr[j];
        curr[j] = curr[i];
        curr[i] = temp;
    }

    static final Random random=new Random();

    static void ruffleSortLong(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static void ruffleSortInt(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            int temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static void ruffleSortChar(char[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            char temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static long binomialCoeff(long n, long k){

        long res = 1;

        // Since C(n, k) = C(n, n-k)
        if (k > n - k)
            k = n - k;

        // Calculate value of
        // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
        for (long i = 0; i < k; ++i) {
            res = (res*(n - i));
            res = (res/(i + 1));
        }

        return res;
    }

    static long mod(long x)
    {
        long y = mod;
        long result = x % y;
        if (result < 0)
        {
            result += y;
        }
        return result;
    }

    static long[] fact;

    public static long inv(long n){
        return power(n, mod-2);
    }

    public static void fact(int n){
        fact = new long[n+1];
        fact[0] = 1;
        for(int j = 1;j<=n;j++)
            fact[j] = (fact[j-1]*(long)j)%mod;
    }

    public static long binom(int n, int k){

        long prod = fact[n];
        prod*=inv(fact[n-k]);
        prod%=mod;
        prod*=inv(fact[k]);
        prod%=mod;
        return prod;
    }

    static long power(long x, long y){
        if (y == 0)
            return 1;
        if (y%2 == 1)
            return (x*power(x, y-1))%mod;
        return power((x*x)%mod, y/2)%mod;
    }

    public static long pow(long n,long p,long m){
        long  result = 1;
        if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            if(result>=m)
                result%=m;
            p >>=1;
            n*=n;
            if(n>=m)
                n%=m;
        }
        return result;
    }

    static void sieve(int n){

        prime = new boolean[n+1];
        for(int i=2;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

    static long abs(long a){
        return Math.abs(a);
    }

    static int abs(int a){
        return Math.abs(a);
    }

    static int max(int a,int b){
        if(a>b)
            return a;
        else
            return b;
    }
    static double max(double a,double b){
        if(a>b)
            return a;
        else
            return b;
    }
    static double min(double a,double b){
        if(a>b)
            return b;
        else
            return a;
    }

    static int min(int a,int b){
        if(a>b)
            return b;
        else
            return a;
    }

    static long max(long a,long b){
        if(a>b)
            return a;
        else
            return b;
    }

    static long min(long a,long b){
        if(a>b)
            return b;
        else
            return a;
    }

    static long sq(long num){
        return num*num;
    }

    static double sq(double num){
        return num*num;
    }

    static long sqrt(long num){
        return (long)Math.sqrt(num);
    }

    static double sqrt(double num){
        return Math.sqrt(num);
    }

    static class FastScanner {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        void readArray(int n) {
            arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextLong();
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {new Main().run();}

    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);
    void run() {
        work();
        out.flush();
    }
    long mod=998244353;
    long gcd(long a,long b) {
        return a==0?b:gcd(b%a,a);
    }
    void work() {
        int n=ni(),k=ni();
        long[][] dp=new long[251][251];
        for(int j=1;j<=k;j++){
            dp[1][j]=1;
        }
        long[][] pow=new long[251][251*251];
        long[][] C=new long[251][251];
        for(int i=1;i<=250;i++){
            pow[i][0]=1;
            for(int j=1;j<251*251;j++){
                pow[i][j]=pow[i][j-1]*i%mod;
            }
        }
        for(int i=0;i<=250;i++){
            for(int j=0;j<=i;j++){
                if(i==0||j==0){
                    C[i][j]=1;
                }else{
                    C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
                }
            }
        }
        for(int j=0;j<=k;j++){
            dp[0][j]=1;
        }
        for(int i=1;i<=n-1;i++){
            for(int j=1;j<=k;j++){
                dp[i][j]=dp[i][j-1];
                for(int p=1;p<=i;p++){
                    dp[i][j]+=dp[i-p][j-1]*C[i][p]%mod*pow[k-j+1][p*(i-p)+(p-1)*p/2]%mod;
                }
            }
        }
        out.println(dp[n-1][k]);
    }

    private ArrayList<Integer>[] ng(int n, int m) {
        ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
        for(int i=0;i<n;i++) {
            graph[i]=new ArrayList<>();
        }
        for(int i=1;i<=m;i++) {
            int s=in.nextInt()-1,e=in.nextInt()-1;
            graph[s].add(e);
            graph[e].add(s);
        }
        return graph;
    }

    private ArrayList<long[]>[] ngw(int n, int m) {
        ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
        for(int i=0;i<n;i++) {
            graph[i]=new ArrayList<>();
        }
        for(int i=1;i<=m;i++) {
            long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
            graph[(int)s].add(new long[] {e,w});
            graph[(int)e].add(new long[] {s,w});
        }
        return graph;
    }

    private ArrayList<int[]>[] ngwi(int n, int m) {
        ArrayList<int[]>[] graph=(ArrayList<int[]>[])new ArrayList[n];
        for(int i=0;i<n;i++) {
            graph[i]=new ArrayList<>();
        }
        for(int i=1;i<=m;i++) {
            int s=ni()-1,e=ni()-1,w=ni();
            graph[s].add(new int[] {e,w});
            graph[e].add(new int[] {s,w});
        }
        return graph;
    }

    private int ni() {
        return in.nextInt();
    }

    private long nl() {
        return in.nextLong();
    }
    private double nd() {
        return in.nextDouble();
    }
    private String ns() {
        return in.next();
    }

    private long[] na(int n) {
        long[] A=new long[n];
        for(int i=0;i<n;i++) {
            A[i]=in.nextLong();
        }
        return A;
    }

    private int[] nia(int n) {
        int[] A=new int[n];
        for(int i=0;i<n;i++) {
            A[i]=in.nextInt();
        }
        return A;
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;
    InputStreamReader input;//no buffer
    public FastReader()
    {
        br=new BufferedReader(new InputStreamReader(System.in));
    }

    public FastReader(boolean isBuffer)
    {
        if(!isBuffer){
            input=new InputStreamReader(System.in);
        }else{
            br=new BufferedReader(new InputStreamReader(System.in));
        }
    }

    public boolean hasNext(){
        try{
            String s=br.readLine();
            if(s==null){
                return  false;
            }
            st=new StringTokenizer(s);
        }catch(IOException e){
            e.printStackTrace();
        }
        return true;
    }

    public String next()
    {
        if(input!=null){
            try {
                StringBuilder sb=new StringBuilder();
                int ch=input.read();
                while(ch=='\n'||ch=='\r'||ch==32){
                    ch=input.read();
                }
                while(ch!='\n'&&ch!='\r'&&ch!=32){
                    sb.append((char)ch);
                    ch=input.read();
                }
                return sb.toString();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        while(st==null || !st.hasMoreElements())//回车，空行情况
        {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt()
    {
        return (int)nextLong();
    }

    public long nextLong() {
        try {
            if(input!=null){
                long ret=0;
                int b=input.read();
                while(b<'0'||b>'9'){
                    b=input.read();
                }
                while(b>='0'&&b<='9'){
                    ret=ret*10+(b-'0');
                    b=input.read();
                }
                return ret;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Long.parseLong(next());
    }

    public double nextDouble()
    {
        return Double.parseDouble(next());
    }
}


import java.util.*;
import java.io.*;

public class _1657_E {
    static final long MOD = 998244353;
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer line = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(line.nextToken());
        int k = Integer.parseInt(line.nextToken());
        long[][][] dp = new long[n][k + 1][n];
        long[][] psum = new long[n][k + 1];
        for(int i = 1; i <= k; i++) {
            dp[1][i][1] = 1;
            psum[1][i] = modadd(psum[1][i - 1], 1);
        }
        long res = 0;
        for(int i = 2; i < n; i++) {
            for(int j = 1; j <= k; j++) {
                psum[i][j] = psum[i][j - 1];
                for(int a = 1; a <= i; a++) {
                    if(a > 1) {
                        long mult = modmult(modmult(i, modinv(a)), binpow(k - j + 1, i - 1));
                        dp[i][j][a] = modmult(dp[i - 1][j][a - 1], mult);
                    }else {
                        long mult = modmult(i, binpow(k - j + 1, i - 1));
                        dp[i][j][a] = modmult(psum[i - 1][j - 1], mult);
                    }
                    psum[i][j] = modadd(psum[i][j], dp[i][j][a]);
                    if(i == n - 1) {
                        res = modadd(res, dp[i][j][a]);
                    }
                }
            }
        }
        out.println(res);
        in.close();
        out.close();
    }
    static long modadd(long a, long b) {
        return (a + b + MOD) % MOD;
    }
    static long modmult(long a, long b) {
        return a * b % MOD;
    }
    static long modinv(long a) {
        return binpow(a, MOD - 2);
    }
    static long binpow(long a, long b) {
        if(b == 0) {
            return 1;
        }
        long small = binpow(a, b / 2);
        if(b % 2 == 0) {
            return modmult(small, small);
        }else {
            return modmult(modmult(small, small), a);
        }
    }
}


import java.util.*;
import java.io.*;

public class _1657_E {
    static final long MOD = 998244353;
    static long[][] pow = new long[255][255];
    static long[] inv = new long[255];
    public static void main(String[] args) throws IOException {
        for(int i = 0; i < 255; i++) {
            long prod = 1;
            for(int j = 0; j < 255; j++) {
                pow[i][j] = prod;
                prod = modmult(prod, i);
            }
            if(i > 0) {
                inv[i] = modinv(i);
            }
        }
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer line = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(line.nextToken());
        int k = Integer.parseInt(line.nextToken());
        long[][][] dp = new long[n][k + 1][n];
        long[][] psum = new long[n][k + 1];
        long res = 0;
        for(int i = 1; i <= k; i++) {
            dp[1][i][1] = 1;
            psum[1][i] = modadd(psum[1][i - 1], 1);
            if(i == n - 1) {
                res = modadd(res, 1);
            }
        }
        for(int i = 2; i < n; i++) {
            for(int j = 1; j <= k; j++) {
                psum[i][j] = psum[i][j - 1];
                for(int a = 1; a <= i; a++) {
                    if(a > 1) {
                        long mult = modmult(modmult(i, inv[a]), pow[k - j + 1][i - 1]);
                        dp[i][j][a] = modmult(dp[i - 1][j][a - 1], mult);
                    }else {
                        long mult = modmult(i, pow[k - j + 1][i - 1]);
                        dp[i][j][a] = modmult(psum[i - 1][j - 1], mult);
                    }
                    psum[i][j] = modadd(psum[i][j], dp[i][j][a]);
                    if(i == n - 1) {
                        res = modadd(res, dp[i][j][a]);
                    }
                }
            }
        }
        out.println(res);
        in.close();
        out.close();
    }
    static long modadd(long a, long b) {
        return (a + b + MOD) % MOD;
    }
    static long modmult(long a, long b) {
        return a * b % MOD;
    }
    static long modinv(long a) {
        return binpow(a, MOD - 2);
    }
    static long binpow(long a, long b) {
        if(b == 0) {
            return 1;
        }
        long small = binpow(a, b / 2);
        if(b % 2 == 0) {
            return modmult(small, small);
        }else {
            return modmult(modmult(small, small), a);
        }
    }
}