/*
I am dead inside
Do you like NCT, sKz, BTS?
5 4 3 2 1 Moonwalk
Imma knock it down like domino
Is this what you want? Is this what you want?
Let's ttalkbocky about that
 */
import static java.lang.Math.*;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1646E
{
    public static void main(String hi[]) throws Exception
    {
        BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(infile.readLine());
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        int[] prime = new int[N+1];
        for(int d=2; d <= N; d++)
            if(prime[d] == 0)
                for(int v=d; v <= N; v+=d)
                    prime[v] = d;
        //preprocess
        boolean[] seen = new boolean[20*(1<<20)];
        int[] dp = new int[20];
        dp[0] = M;
        for(int v=1; v <= M; v++)
            seen[v] = true;
        for(int i=1; i < 20; i++)
        {
            dp[i] = dp[i-1];
            for(int v=1; v <= M; v++)
                if(!seen[(i+1)*v])
                {
                    seen[(i+1)*v] = true;
                    dp[i]++;
                }
        }
        long res = 1L;
        for(int v=2; v <= N; v++)
            if(prime[v] == v)
            {
                int curr = 0;
                int temp = v;
                while(temp*v <= N)
                {
                    curr++;
                    temp *= v;
                }
                res += dp[curr];
            }
        System.out.println(res);
    }
    public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
    {
        int[] arr = new int[N];
        st = new StringTokenizer(infile.readLine());
        for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
        return arr;
    }
}


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

public class PowerBoard {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] spf = new int[1_000_001];
        Arrays.fill(spf, 1);
        for (int i=2; i<=1_000; i++) if (spf[i]==1)
                for (int j=i; j<=1_000_000; j+=i) if (spf[j]==1)
                        spf[j] = i;
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        HashSet<Integer>[] sets = new HashSet[20];
        for (int i=0; i<20; i++) sets[i] = new HashSet<>();
        for (int i=1; i<20; i++) {
            sets[i] = (HashSet<Integer>) sets[i-1].clone();
            for (int j=1; j<=M; j++) {
                sets[i].add(i*j);
            }
        }
        long cnt = 1;
        for (int p=2; p<=N; p++) {
            if (spf[p]!=p) continue;
            long cur = p;
            int j;
            for (j=2; j<20; j++) {
                cur *= p;
                if (cur > M) {
                    j--;
                    break;
                }
            }
            cnt += sets[j].size();
        }
        System.out.println(cnt);
    }
}


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=1000000007;
    long gcd(long a,long b) {
        return a==0?b:gcd(b%a,a);
    }
    long inf=Long.MAX_VALUE/3;
    void work() {
        long n=nl(),m=nl();
        long ret=n*m-(m-1);
        int[] A=new int[200000];
        for(int i=1;i<200000;i++)A[i]=i;
        for(int i=2;i<200000;i++){
            if(A[i]==i){
                for(int j=i;(long)i*j<200000;j++){
                    if(A[i*j]==i*j){
                        A[i*j]=i;
                    }
                }
            }
        }
        boolean[] vis=new boolean[1000003];
        for(long i=2;i<=n;i++){
            if(vis[(int)i])continue;
            for(long j=2,cur=i*i;cur<=n;cur*=i){
                int pre=A[(int)j];
                long v=m/pre;
                ret-=v;
                vis[(int)cur]=true;
            }
        }
        out.println(ret);
    }

    @SuppressWarnings("unused")
    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 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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Cp {
	public static int primeFactors(int number) {
		  int n = number;
		  int count = 0;
		  for (int i = 2; i <= n; i++) {
		   while (n % i == 0) {
			   count++;
			   n /= i;
		   }
		  }
		  return count;
		 }
	public static long ways(long n) {
		if(n==1) {
			return 3;
		}else {
			long k = Pow(2,n) + ways(n-1);
			return k;
		}
	}

	public static void main(String[] args) {

		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			System.out.println((modPow(2,k,mod)%mod * (n-1)%mod)%mod);
		}
	}

static FastReader sc=new FastReader();
static int dp[][];
static int mod=1000000007;

public static long Pow(long base, long exp) {

	 if (exp == 0)
	 return 1;

	 else if (exp == 1)
	 return base;

	 else if (exp%2 == 0)
	 return Pow(base*base, exp/2);

	 else
	 return base*Pow(base, exp-1);
	}
public static long modPow(long base, long exp, long n) {

	 base = base%n;

	 if (exp == 0)
	 return 1;

	 else if (exp == 1)
	 return base;

	 else if (exp%2 == 0)
	 return modPow(base*base%n, exp/2, n);

	 else
	 return base*modPow(base, exp-1, n)%n;
	}

static int go(int A[],int B[],int gcd,int i) {
	if(i==A.length) {
		for(int j=2;j*j<=gcd;j++) {
			if(gcd%j==0) {
				return j;
			}
		}
		return -1;
	}

	int g=gcd(A[i],gcd);
	int h=gcd(B[i],gcd);
	int op1=go(A, B, g, i+1);
	if(op1==-1) {
		op1=go(A, B, h, i+1);
		return op1;
	}
	else
		return op1;
}
static int[] input(int n) {
	int A[]=new int[n];
	for(int i=0;i<n;i++) {
		A[i]=sc.nextInt();
	}
	return A;
}
static long[] inputL(int n) {
	long A[]=new long[n];
	for(int i=0;i<n;i++) {
		A[i]=sc.nextLong();
	}
	return A;
}
static String[] inputS(int n) {
	String A[]=new String[n];
	for(int i=0;i<n;i++) {
		A[i]=sc.next();
	}
	return A;
}
static long sum(int A[]) {
	long sum=0;
	for(int i : A) {
		sum+=i;
	}
	return sum;
}
static long sum(long A[]) {
	long sum=0;
	for(long i : A) {
		sum+=i;
	}
	return sum;
}
static void input(int A[],int B[]) {
	for(int i=0;i<A.length;i++) {
		A[i]=sc.nextInt();
		B[i]=sc.nextInt();
	}
}
static int[][] input(int n,int m){
	int A[][]=new int[n][m];
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			A[i][j]=i();
		}
	}
	return A;
}
static char[][] charinput(int n,int m){
	char A[][]=new char[n][m];
	for(int i=0;i<n;i++) {
		String s=s();
		for(int j=0;j<m;j++) {
			A[i][j]=s.charAt(j);
		}
	}
	return A;
}
static int max(int A[]) {
	int max=Integer.MIN_VALUE;
	for(int i=0;i<A.length;i++) {
		max=Math.max(max, A[i]);
	}
	return max;
}
static int min(int A[]) {
	int min=Integer.MAX_VALUE;
	for(int i=0;i<A.length;i++) {
		min=Math.min(min, A[i]);
	}
	return min;
}
static long max(long A[]) {
	long max=Long.MIN_VALUE;
	for(int i=0;i<A.length;i++) {
		max=Math.max(max, A[i]);
	}
	return max;
}
static long min(long A[]) {
	long min=Long.MAX_VALUE;
	for(int i=0;i<A.length;i++) {
		min=Math.min(min, A[i]);
	}
	return min;
}
static long [] prefix(long A[]) {
	long p[]=new long[A.length];
	p[0]=A[0];
	for(int i=1;i<A.length;i++)
		p[i]=p[i-1]+A[i];
	return p;
}
static long [] prefix(int A[]) {
	long p[]=new long[A.length];
	p[0]=A[0];
	for(int i=1;i<A.length;i++)
		p[i]=p[i-1]+A[i];
	return p;
}
static long [] suffix(long A[]) {
	long p[]=new long[A.length];
	p[A.length-1]=A[A.length-1];
	for(int i=A.length-2;i>=0;i--)
		p[i]=p[i+1]+A[i];
	return p;
}
static long [] suffix(int A[]) {
	long p[]=new long[A.length];
	p[A.length-1]=A[A.length-1];
	for(int i=A.length-2;i>=0;i--)
		p[i]=p[i+1]+A[i];
	return p;
}
static long mod(long x) {
	int mod=1000000007;
	return ((x%mod + mod)%mod);
}
static String reverse(String s) {
	StringBuffer p=new StringBuffer(s);
	p.reverse();
	return p.toString();
}

static int i() {
	return sc.nextInt();
}
static String s() {
	return sc.next();
}
static long l() {
	return sc.nextLong();
}
static void sort(int[] A){
	int n = A.length;
	Random rnd = new Random();
	for(int i=0; i<n; ++i){
		int tmp = A[i];
		int randomPos = i + rnd.nextInt(n-i);
		A[i] = A[randomPos];
		A[randomPos] = tmp;
	}
	Arrays.sort(A);
}
static void sort(long[] A){
	int n = A.length;
	Random rnd = new Random();
	for(int i=0; i<n; ++i){
		long tmp = A[i];
		int randomPos = i + rnd.nextInt(n-i);
		A[i] = A[randomPos];
		A[randomPos] = tmp;
	}
	Arrays.sort(A);
}
static String sort(String s) {
	Character ch[]=new Character[s.length()];
	for(int i=0;i<s.length();i++) {
		ch[i]=s.charAt(i);
	}
	Arrays.sort(ch);
	StringBuffer st=new StringBuffer("");
	for(int i=0;i<s.length();i++) {
		st.append(ch[i]);
	}
	return st.toString();
}
static HashMap<Integer,Integer> hash(int A[]){
	HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
	for(int i : A) {
		if(map.containsKey(i)) {
			map.put(i, map.get(i)+1);
		}
		else {
			map.put(i, 1);
		}
	}
	return map;
}
static TreeMap<Integer,Integer> tree(int A[]){
	TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();
	for(int i : A) {
		if(map.containsKey(i)) {
			map.put(i, map.get(i)+1);
		}
		else {
			map.put(i, 1);
		}
	}
	return map;
}
static boolean prime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	double sq=Math.sqrt(n);

	for (int i = 5; i <= sq; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return false;
	return true;
}
static boolean prime(long n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	double sq=Math.sqrt(n);

	for (int i = 5; i <= sq; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return false;
	return true;
}
static int gcd(int a, int b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
static long gcd(long a, long b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
static class Pair implements Comparable<Pair>
{
	int x;
	int y;
	Pair(int x,int y){
		this.x=x;
		this.y=y;
	}
	@Override
	public int compareTo(Pair o) {
		if(this.x>o.x)
			return 1;
		else if(this.x<o.x)
			return -1;
		else {
			if(this.y>o.y)
				return 1;
			else if(this.y<o.y)
				return -1;
			else
				return 0;
		}
	}
}
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;
	}
}

static int multiply(int x, int res[], int res_size) {

	int carry = 0;

	for (int i = 0; i < res_size; i++) {
	int prod = res[i] * x + carry;

	res[i] = prod % 10;

	carry = prod / 10;
	}

	while (carry > 0) {
	res[res_size] = carry % 10;
	carry = carry / 10;
	res_size++;
	}
	return res_size;
}

public static void power(int x, int n) {

	if(n == 0 ){
	System.out.print("1");
	return;
}

	int MAX = 1000001;
	int res[] = new int[MAX];
	int res_size = 0;
	int temp = x;

	while (temp != 0) {
	res[res_size++] = temp % 10;
	temp = temp / 10;
	}

	for (int i = 2; i <= n; i++)
	res_size = multiply(x, res, res_size);

	System.out.print(x + "^" + n + " = ");
	for (int i = res_size - 1; i >= 0; i--)
	System.out.print(res[i]);
}

}


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

public class Main {

    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());
        }
    }

    public static void main(String[] args) {
        FastReader fs = new FastReader();
        int t = fs.nextInt();
        while(t-->0) {
            int n = fs.nextInt();
            int k = fs.nextInt();

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


import java.util.*;
public class E{

public static void main(String [] args){
       Scanner in=new Scanner (System.in);
      int test=in.nextInt();
      for (int pop=0;pop<test;pop++){
           int n=in.nextInt();
           int k=in.nextInt();
           int and=1;
           for(int h=0;h<k;h++){
               and*=n;
               and%=1000000007;
}
System.out.println(and);
}

}
}


import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import java.math.*;
//
public class Main{
	private static int[] input() {
		int n=in.nextInt();
		int[]arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=in.nextInt();
		}
		return arr;
	}
	private static int inte() {
		return in.nextInt();
	}
	private static long lon() {
		return in.nextLong();
	}
	public static void main(String[] args) {
	      TaskA solver = new TaskA();
	      int t = in.nextInt();
	      for (int i = 1; i <= t ; i++) {
	    	  solver.solve(t, in, out);
	      }
//	      solver.solve(1, in, out);
	      out.flush();
	    out.close();
	  }

	static ArrayList<Integer>[]graph;
	static int[][] dp;
	 static class TaskA {
	      public void solve(int testNumber, InputReader in, PrintWriter out) {
	    	long n=in.nextLong();long k=in.nextLong();long x=n;
	    	for(int i=0;i<k;i++) {
	    		n=(n*x)%mod;
	    	}
	    	println(n);
	      }
	 }
	 public static int getFirstSetBitPos(int n)
	    {
	        return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1;
	    }

	 private static boolean isPalindrome(String s) {
		 StringBuilder sb=new StringBuilder(s);
		 if(sb.reverse().toString().equals(s))
			 return true;
		 return false;
	 }
	private static void dfs(int root,Pair[]p,int parent,int[][]dp) {
		int ans1=0;int ans2=0;
		for(int i:graph[root]) {
			if(i!=parent) {
				dfs(i,p,root,dp);
			}
		}
		for(int i:graph[root]) {
			if(i!=parent) {
				int val1=Math.abs(p[root].first-p[i].first)+dp[i][0];
				int val2=Math.abs(p[root].first-p[i].second)+dp[i][1];
				ans1+=Math.max(val1, val2);
			}
		}
		for(int i:graph[root]) {
			if(i!=parent) {
				int val1=Math.abs(p[root].second-p[i].first)+dp[i][0];
				int val2=Math.abs(p[root].second-p[i].second)+dp[i][1];
				ans2+=Math.max(val1, val2);
			}
		}
		dp[root][0]=ans1;dp[root][1]=ans2;
	}
	 private static void printArr(int[] arr) {
	        for (int i = 0; i < arr.length; i++) {
	            print(arr[i] + " ");
	        }
	        	print("\n");
	    }
	 private static String rev(String s) {
		 String st="";
		 for(int i=s.length()-1;i>=0;i--) {
			 st+=s.charAt(i);
		 }
		 return st;
	 }
	 private static int[] rev(int[]arr) {
		 int[]a=arr.clone();
		 for(int i=0;i<arr.length;i++) {
			 a[i]=arr[arr.length-i-1];
		 }
		 return arr;
	 }

//	 for (Map.Entry<Integer,ArrayList<Integer>> entry : hm.entrySet()) {
//	 ArrayList<Integer>a=entry.getValue();
//
// }

	 static long ceil(long a,long b) {
		  return (a/b + Math.min(a%b, 1));
	 }
	 static long pow(long b, long e) {
	        long ans = 1;
	        while (e > 0) {
	            if (e % 2 == 1)
	                ans = ans * b % mod;
	            e >>= 1;
	            b = b * b % mod;
	        }
	        return ans;
	    }

	 static void sortDiff(Pair arr[])
	    {
	        // Comparator to sort the pair according to second element
	        Arrays.sort(arr, new Comparator<Pair>() {
	            @Override public int compare(Pair p1, Pair p2)
	            {	if(p1.first==p2.first) {
	            	return (p1.second-p1.first)-(p2.second-p1.first);
	            }
	            	return (p1.second-p1.first)-(p2.second-p2.first);
	            }
	        });
	    }

	 static void sortF(Pair arr[])
	    {
	        // Comparator to sort the pair according to second element
	        Arrays.sort(arr, new Comparator<Pair>() {
	            @Override public int compare(Pair p1, Pair p2)
	            {	if(p1.first==p2.first) {
	            	return p1.second-p2.second;
	            }
	                return p1.first - p2.first;
	            }
	        });
	    }

	 static long[] fac;
	    static long mod = (long) 1000000007;

	    static void initFac(long n) {
	        fac = new long[(int)n + 1];
	        fac[0] = 1;
	        for (int i = 1; i <= n; i++) {
	            fac[i] = (fac[i - 1]  * i) % mod;
	        }
	    }

	    static long nck(int n, int k) {
	        if (n < k)
	            return 0;
	        long den = inv((int) (fac[k] * fac[n - k] % mod));
	        return fac[n] * den % mod;
	    }

	    static long inv(long x) {
	        return pow(x, mod - 2);
	    }

	    static void sort(int[] a) {
	        ArrayList<Integer> q = new ArrayList<>();
	        for (int i : a) q.add(i);
	        Collections.sort(q);
	        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
	    }

	    static void sort(long[] a) {
	        ArrayList<Long> q = new ArrayList<>();
	        for (long i : a) q.add(i);
	        Collections.sort(q);
	        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
	    }

	 public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) {
			Queue<Integer>q=new LinkedList<>();
			q.add(source);
			visited[source]=true;
			int distance=0;
			while(!q.isEmpty()) {
				int curr=q.poll();
				distance++;
				for(int neighbour:a[curr]) {
					if(!visited[neighbour]) {
						visited[neighbour]=true;
						q.add(neighbour);
					}
				}
			}
			return distance;
		}
	 public static Set<Integer>factors(int n){
		 Set<Integer>ans=new HashSet<>();
		 ans.add(1);
		 for(int i=2;i*i<=n;i++) {
			 if(n%i==0) {
				 ans.add(i);
				 ans.add(n/i);
			 }
		 }
		 return ans;
	 }
	public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) {
		boolean[]visited=new boolean[a.length];
		int[]parent=new int[a.length];
		Queue<Integer>q=new LinkedList<>();
		int distance=0;
		q.add(source);
		visited[source]=true;
		parent[source]=-1;
		while(!q.isEmpty()) {
			int curr=q.poll();
			if(curr==destination) {
				break;
			}
			for(int neighbour:a[curr]) {
				if(neighbour!=-1&&!visited[neighbour]) {
					visited[neighbour]=true;
					q.add(neighbour);
					parent[neighbour]=curr;
				}
			}
		}
		int cur=destination;
		while(parent[cur]!=-1) {
			distance++;
			cur=parent[cur];
		}
		return distance;
	}
	 static int bs(int size,int[]arr) {
		 int x = -1;
    	 for (int b = size/2; b >= 1; b /= 2) {
        	 while (!ok(arr));
        	 }
    	 int k = x+1;
    	 return k;
	 }

	 static boolean ok(int[]x) {
		 return false;
	 }

	 public static int solve1(ArrayList<Integer> A) {
		 long[]arr =new long[A.size()+1];
		 int n=A.size();
		 for(int i=1;i<=A.size();i++) {
			 arr[i]=((i%2)*((n-i+1)%2))%2;
			 arr[i]%=2;
		 }
		 int ans=0;
		 for(int i=0;i<A.size();i++) {
			 if(arr[i+1]==1) {
				 ans^=A.get(i);
			 }
		 }
		 return ans;
	   }

	     public static String printBinary(long a) {
	    	 String str="";
	    	 for(int i=31;i>=0;i--) {
	    		 if((a&(1<<i))!=0) {
	    			 str+=1;
	    		 }

	    		 if((a&(1<<i))==0 && !str.isEmpty()) {
	    			 str+=0;
	    		 }

	    	 }
	    	 return str;
	     }

		 public static String reverse(long a) {
		        long rev=0;
		        String str="";
		        int x=(int)(Math.log(a)/Math.log(2))+1;
		        for(int i=0;i<32;i++) {
		        	rev<<=1;
		        	if((a&(1<<i))!=0) {
		        		rev|=1;
		        		str+=1;
		        	}
		        	else {
		        		str+=0;
		        	}
		        }
		        return str;
			}

	 ////////////////////////////////////////////////////////

	 static void sortS(Pair arr[])
	    {
	        // Comparator to sort the pair according to second element
	        Arrays.sort(arr, new Comparator<Pair>() {
	            @Override public int compare(Pair p1, Pair p2)
	            {
	                return p1.second - p2.second;
	            }
	        });
	    }

	 static class Pair implements Comparable<Pair>
	 {
	   int first ;int second  ;

	   public  Pair(int x, int y)
	   {
	       this.first = x ;this.second = y ;
	   }

	   @Override
	  public boolean equals(Object obj)
	  {
	      if(obj == this)return true  ;

	      if(obj == null)return false  ;

	      if(this.getClass() != obj.getClass()) return false ;

	      Pair other  = (Pair)(obj) ;

	      if(this.first != other.first)return false  ;
	      if(this.second != other.second)return false  ;

	      return true  ;

	  }

	     @Override

	     public int hashCode()
	     {
	         return this.first^this.second  ;
	     }

	 @Override
	 	public String toString() {

	 	String ans = "" ;ans  += this.first ;	ans += " ";	ans += this.second ;
	 	return ans  ;
	 	}

	@Override
	public int compareTo(Main.Pair o) {
		{	if(this.first==o.first) {
        	return this.second-o.second;
        }
            return this.first - o.first;
        }
	}

	 }
	 //////////////////////////////////////////////////////////////////////////

	 static int nD(long num) {
		 String s=String.valueOf(num);
		 return s.length();
	 }

	 static int CommonDigits(int x,int y) {
		 String s=String.valueOf(x);
		 String s2=String.valueOf(y);
		 return 0;
	 }

	 static int lcs(String str1, String str2, int m, int n)
	    {
	        int L[][] = new int[m + 1][n + 1];
	        int i, j;

	        // Following steps build L[m+1][n+1] in
	        // bottom up fashion. Note that L[i][j]
	        // contains length of LCS of str1[0..i-1]
	        // and str2[0..j-1]
	        for (i = 0; i <= m; i++) {
	            for (j = 0; j <= n; j++) {
	                if (i == 0 || j == 0)
	                    L[i][j] = 0;

	                else if (str1.charAt(i - 1)
	                         == str2.charAt(j - 1))
	                    L[i][j] = L[i - 1][j - 1] + 1;

	                else
	                    L[i][j] = Math.max(L[i - 1][j],
	                                       L[i][j - 1]);
	            }
	        }

	        // L[m][n] contains length of LCS
	        // for X[0..n-1] and Y[0..m-1]
	        return L[m][n];
	    }

	 /////////////////////////////////
	 boolean IsPowerOfTwo(int x)
	 {
	     return (x != 0) && ((x & (x - 1)) == 0);
	 }
	 ////////////////////////////////

	 static long power(long a,long b,long m ) {
		 long ans=1;
		 while(b>0) {
			 if(b%2==1) {
				 ans=((ans%m)*(a%m))%m; b--;
			 }
			 else {
				 a=(a*a)%m;b/=2;
			 }

		 }
		 return ans%m;
	 }
	 ///////////////////////////////
	 public static boolean repeatedSubString(String string) {
		    return ((string + string).indexOf(string, 1) != string.length());
		}
	 static int search(char[]c,int start,int end,char x) {
		 for(int i=start;i<end;i++) {
			 if(c[i]==x) {return i;}
		 }
		 return -2;
	 }
	 ////////////////////////////////

	 static long gcd(int a, int b) {
	        while (b != 0) {
	            int t = b;
	            b = a % b;
	            a = t;
	        }
	        return a;
	    }

	 static long fac(long a)
	 {
	     if(a== 0L || a==1L)return 1L ;

	     return a*fac(a-1L) ;
	 }

	 static ArrayList al() {
		 ArrayList<Integer>a =new ArrayList<>();
			return a;
		}

	static HashSet h() {
			return new HashSet<Integer>();
		}
	static void debug(long[][]a) {
		int n= a.length;
		for(int i=0;i<a.length;i++) {
	  		for(int j=0;j<a[0].length;j++) {
	  			out.print(a[i][j]+" ");
	  		}
	  		out.print("\n");
	  	}
	}
	static void debug(int[]a) {
			out.println(Arrays.toString(a));
		}

	static void debug(ArrayList<Integer>a) {
				out.println(a.toString());
		}

	static boolean[]seive(int n){
		boolean[]b=new boolean[n+1];
		 for (int i = 2; i <= n; i++)
	            b[i] = true;

		for(int i=2;i*i<=n;i++) {
			if(b[i]) {
				for(int j=i*i;j<=n;j+=i) {
					b[j]=false;
				}
			}

		}
		return b;
	}

	 static int longestIncreasingSubseq(int[]arr) {
		  int[]sizes=new int[arr.length];
		  Arrays.fill(sizes, 1);
		  int max=1;
		  for(int i=1;i<arr.length;i++) {
			  for(int j=0;j<i;j++) {
				  if(arr[j]<arr[i]) {
					  sizes[i]=Math.max(sizes[i],sizes[j]+1);
					  max=Math.max(max, sizes[i]);
				  }
			  }
		  }
		  return max;
	 }

	 public static ArrayList primeFactors(long n)
	    {
		    ArrayList<Long>h= new ArrayList<>();
	        // Print the number of 2s that divide n
	        if(n%2 ==0) {h.add(2L);}

	        // n must be odd at this point.  So we can
	        // skip one element (Note i = i +2)
	        for (long i = 3; i <= Math.sqrt(n); i+= 2)
	        {
	            if(n%i==0) {h.add(i);}
	        }
	        if (n > 2)
	            h.add(n);
	        return h;
	    }

	 static boolean Divisors(long n){
		 if(n%2==1) {
			 return true;
		 }
	     for (long i=2; i<=Math.sqrt(n); i++){
	            if (n%i==0 && i%2==1){
	                   return true;
	            }
	        }
	     return false;
	    }

	static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

    public static void superSet(int[]a,ArrayList<String>al,int i,String s) {
    	if(i==a.length) {
    		al.add(s);
    		return;
    	}
    	superSet(a,al,i+1,s);
    	superSet(a,al,i+1,s+a[i]+" ");
    }

	public static long[] makeArr() {
		long size=in.nextInt();
		long []arr=new long[(int)size];
		for(int i=0;i<size;i++) {
			arr[i]=in.nextInt();
		}
		return arr;
	}

	public static long[] arr(int n) {
		long []arr=new long[n+1];
		for(int i=1;i<n+1;i++) {
			arr[i]=in.nextLong();
		}
		return arr;
	}

  public static void sort(long arr[], int l, int r)
  {
      if (l < r)
      {
          // Find the middle point
          int m = (l+r)/2;

          // Sort first and second halves
          sort(arr, l, m);
          sort(arr , m+1, r);

          // Merge the sorted halves
          merge(arr, l, m, r);
      }
  }
  static void println(long x) {
		 out.println(x);
	 }
  static void print(long c) {
		 out.print(c);
	 }
  static void print(int c) {
		 out.print(c);
	 }
	 static void println(int x) {
		 out.println(x);
	 }
	 static void print(String s) {
		 out.print(s);
	 }
	 static void println(String s) {
		 out.println(s);
	 }
public static void merge(long arr[], int l, int m, int r)
  {
      // Find sizes of two subarrays to be merged
      int n1 = m - l + 1;
      int n2 = r - m;

      /* Create temp arrays */
      long L[] = new long[n1];
      long R[] = new long[n2];

      //Copy data to temp arrays
      for (int i=0; i<n1; ++i)
          L[i] = arr[l + i];
      for (int j=0; j<n2; ++j)
          R[j] = arr[m + 1+ j];

      /* Merge the temp arrays */

      // Initial indexes of first and second subarrays
      int i = 0, j = 0;

      // Initial index of merged subarry array
      int k = l;
      while (i < n1 && j < n2)
      {
          if (L[i] <= R[j])
          {
              arr[k] = L[i];
              i++;
          }
          else
          {
              arr[k] = R[j];
              j++;
          }
          k++;
      }

      /* Copy remaining elements of L[] if any */
      while (i < n1)
      {
          arr[k] = L[i];
          i++;
          k++;
      }

      /* Copy remaining elements of R[] if any */
      while (j < n2)
      {
          arr[k] = R[j];
          j++;
          k++;
      }
  }

public static void reverse(int[] array)
{
    int n = array.length;
    for (int i = 0; i < n / 2; i++) {
        int temp = array[i];
        array[i] = array[n - i - 1];
        array[n - i - 1] = temp;
    }
}

  public static long nCr(int n,int k)
  {
      long ans=1L;
      k=k>n-k?n-k:k;

      for( int j=1;j<=k;j++,n--)
      {
          if(n%j==0)
          {
              ans*=n/j;
          }else
          if(ans%j==0)
          {
              ans=ans/j*n;
          }else
          {
              ans=(ans*n)/j;
          }
      }
      return ans;
  }

  static int searchMax(int index,long[]inp) {
	  while(index+1<inp.length &&inp[index+1]>inp[index]) {
		  index+=1;
	  }
	  return index;
  }
  static int searchMin(int index,long[]inp) {
	  while(index+1<inp.length &&inp[index+1]<inp[index]) {
		  index+=1;
	  }
	  return index;
  }
  public class ListNode {
	       int val;
	       ListNode next;
	       ListNode() {}
	       ListNode(int val) { this.val = val; }
	       ListNode(int val, ListNode next) { this.val = val; this.next = next; }
	   }
  static class Pairr implements Comparable<Pairr>{
		 private int index;
		 private int cumsum;
		 private ArrayList<Integer>indices;
		 public Pairr(int index,int cumsum) {
			 this.index=index;
			 this.cumsum=cumsum;
			 indices=new ArrayList<Integer>();
		 }
		 public int compareTo(Pairr other) {
			 return Integer.compare(cumsum, other.cumsum);
		 }
	 }

  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());
      }
  }
}


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

public class Extras {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        long mod = 10^9 + 7;
        while (t-- > 0) {

            String[] input = br.readLine().split(" ");
            int n = Integer.parseInt(input[0]);
            int k = Integer.parseInt(input[1]);
            long ans = 1;
            for (int i = 0; i < k; i++) {
                ans = (ans * n) % mod;
            }
            System.out.println(ans);
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class B_Rnd716_AND0SumBig
{
	static long n, k;
	static long MOD = (long) ((1e9) + 7);
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		String[] in;
		int tt = parse(scan.readLine());

		for(int t = 0; t < tt; t++)
		{
			in = scan.readLine().split(" ");
			n = parse(in[0]);
			k = parse(in[1]);

			out.println(solve(n, k));
		}

		out.flush();
	}

	private static long solve(long n, long k)
	{
		// nChoose(n-1) is n
		// choose n bits to turn on in the array for each bit digit

		if(n == 1) return 0;

		long ans = 1;
		for(int i = 0; i < k; i++)
			ans = (ans * n) % MOD;

		return ans;
	}

	public static int parse(String num)
	{
		return Integer.parseInt(num);
	}
}


import java.io.PrintWriter;
import java.util.Scanner;

public class Prob1514B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int t = sc.nextInt();
		while(t-->0) {
			long n = sc.nextLong(), k = sc.nextInt();
			long ans = 1;
			String s = "1";

			for(int i = 0; i < k; i++) {
				ans *= n;
				ans = (long) (ans % (Math.pow(10, 9)+7));

				pw.println(ans);
			}
		}

		sc.close();
		pw.close();
	}
}


import java.io.*;
import java.util.*;
public class Main {
  public static void main(String[] args) throws IOException{
    Scanner s = new Scanner(System.in);
    int b = 10^9+7;
    int total = s.nextInt();
    for(int i = 0; i < total; i++){
      int n = s.nextInt();
      int k = s.nextInt();
      int ans = n*k;
      System.out.println(ans%b);
    }
  }
}


import java.util.*;

public class CBR79B {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int t = s.nextInt();

		int c=(int) (1e9+7);
		while (t-- > 0) {
			long n = s.nextLong();
			long k = s.nextLong();

			long ans = (long) Math.pow(n, k);

			System.out.println(ans%c);
		}
	}
}


import java.util.*;

public class BigZero {
    static long MOD= (long) (Math.pow(10,9)+7);
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int t=sc.nextInt();
        while (t-->0) {
            long n=sc.nextLong();
            long k=sc.nextLong();
            System.out.println((long)Math.pow(n, k)% MOD);

        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class And0BigSum {
    long modPow(long a, long e, long mod)    // O(log e)
    {
        a %= mod;
        long res = 1;
        while (e > 0) {
            if ((e & 1) == 1)
                res = (res * a) % mod;
            a = (a * a) % mod;
            e >>= 1;
        }
        return res;
    }

    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    long L_INF = (1L << 60L);
    int ans;

    void solve() {
        int n = ni();
        int k = ni();
        long p = 1, ans = 0;
        int mod = 1000000007;
        if(n==1){
            pw.println(0);
            return;
        }
        p = modPow(n,k,mod);
        pw.println(p);
    }

    void run() throws Exception {
        //		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        is = System.in;
        pw = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        int t = ni();
        while (t-- > 0)
            solve();
        pw.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new And0BigSum().run();
    }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}


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

    public class Test{

        static FastReader scan;

        static void solve(){

            long b=scan.nextLong();
            long p=scan.nextLong();
            System.out.println(power(b,p,100000000+7));
        }

        public static void main (String[] args) throws java.lang.Exception{
            scan=new FastReader();
            int t=scan.nextInt();
            while(t-->0){
                solve();
            }
        }

        static void printLong(long []arr){
            for(long x:arr)System.out.print(x+" ");
        }

        static void printInt(int []arr){
            for(int x:arr)System.out.print(x+" ");
        }

        static void scanInt(int []arr){
            for(int i=0;i<arr.length;i++){
                arr[i]=scan.nextInt();
            }
        }

        static void scanLong(long []arr){
            for(int i=0;i<arr.length;i++){
                arr[i]=scan.nextLong();
            }
        }

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

        static class Pair implements Comparable<Pair>{
            int wt;
            int idx;
            Pair(int x,int y){
                this.wt=x;
                this.idx=y;
            }
            @Override
            public int compareTo(Pair x){
                return this.wt-x.wt;
            }

            public String toString(){
                return "("+wt+" "+idx+")";
            }
        }

        static long power(long x, long y, long p){
            long res = 1;

            x = x % p;

            if (x == 0)
              return 0;

            while (y > 0){
                if ((y & 1) != 0)
                res = (res * x) % p;

                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }
}


import java.util.*;

public class Solution {

	public static final long MOD = 1_000_000_000L + 7;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int t = scanner.nextInt();

		for (int i=0; i<t; i++) {
			long n, k;
			n = scanner.nextLong();
			k = scanner.nextLong();

			long pow = 1;

			for (int j=0; j<n; j++) {
				pow = (pow << 1) % MOD;
			}

			System.out.println((long) Math.pow(2, pow - 2) % MOD);
		}

		scanner.close();
	}
}


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

public class Solution {

	static int  moduloMultiplication(int  a,
            int b, int  mod)
{

// Initialize result
int res = 0;

// Update a if it is more than
// or equal to mod
a %= mod;

while (b > 0)
{

// If b is odd, add a with result
if ((b & 1) > 0)
{
res = (res + a) % mod;
}

// Here we assume that doing 2*a
// doesn't cause overflow
a = (2 * a) % mod;

b >>= 1; // b = b / 2
}
return res;
}
	public static int countPairs(int n) {
		int count=0;
		for(int i=1;i<=(n/2);i++) {
			if((i & (n-i))==0) {
				count++;
//				System.out.println(i+" "+(n-i));
			}
		}
		return count;
	}

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int t=fs.nextInt();
		while(t-->0) {
			int n=fs.nextInt();
			int k=fs.nextInt();
			int m=1000000007;
			int count=countPairs((1<<k)-1);
//			System.out.println(count);
			long total=n+moduloMultiplication(moduloMultiplication(n,n-1,m),count,m);
			System.out.println(total);
		}
	}

	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();
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

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

		int[][] readArray(int n,int m) {
			int[][] a=new int[n][m];
			for (int i=0; i<n; i++) for(int j=0; j<m; j++) a[i][j]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}


import java.util.*;

import jdk.internal.net.http.common.Log;

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

public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        while (t > 0) {
            t--;
            int n = s.nextInt();
            int k = s.nextInt();
            long ans = 1;
            long base = n;
            long MOD = 1000000007;
            while (k != 0) {
                if ((k & 1) == 1)
                    ans = ans * base % MOD;
                base = base * base % MOD;
                k >>= 1;
            }
            System.out.println(ans);
        }
        s.close();
    }
}


import java.util.* ;
import java.io.* ;
public class a4 {

    public static String solve(int n ,int k)
    {
        String ans = "" ;
        ans  = String.valueOf((((long)(Math.pow(n,k))))%(1000000007)) ;
        return ans ;
    }
    public static void main(String[] args) {

        InputStream inputStream = System.in;
        Scanner sc = new Scanner(System.in) ;
        InputReader in = new InputReader(inputStream);
        try{
            int t= in.nextInt();
            while(t-->0)
            {
                int n = in.nextInt();
                int k = in.nextInt() ;

               System.out.println( solve(n,k) );
            }
        }
        catch(Exception e)
        {

        }

    }
}

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 String nextLine()
    {
        return (String)next() ;
    }
    public long nextLong(){return Long.parseLong(next());}
    public double nextDouble(){return Double.parseDouble(next());}
}


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 CodeForces {
    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 gcd(int a, int b) {
        if(b == 0) {
            return a;
        }
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n = in.nextInt();
        int k = in.nextInt();
        int mod = 1000000000+7;
        long ans = 1L;
        int i;
        for(i=0;i<k;i++) {
            ans = (ans*n)%mod;
        }
        System.out.println(ans);

    }
}


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

public class CodeF1
{

   // .....................................input stuff started....................................
private static StringTokenizer st;

    public static void nextLine(BufferedReader br) throws IOException
    {
        st = new StringTokenizer(br.readLine());
    }

    public static int nextInt()
    {
        return Integer.parseInt(st.nextToken());
    }

    public static String next()
    {
        return st.nextToken();
    }

    public static long nextLong()
    {
        return Long.parseLong(st.nextToken());
    }

    public static double nextDouble()
    {
        return Double.parseDouble(st.nextToken());
    }

       // .....................................input stuff ends....................................

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    static boolean prime[];
    public static void genSeive(){
        prime=new boolean[1000001];
        Arrays.fill(prime,true);
        prime[0]=false;
        prime[1]=false;

        for(int i=2;i*i<=1000000;i++)
        	if(prime[i])
        		for(int j=2*i;j<=1000000;j+=i)
                	prime[j]=false;

    }

    public static void solve() throws IOException{
        nextLine(br);
        long mod=1000000007;
        int n=nextInt();
       	int k=nextInt();

       	long pairs=(long)Math.pow(2,k)/2;

       	long perm=(long)((n%mod)*((n-1)%mod))%mod;

         out.append(((pairs%mod)*(perm%mod))%mod+"\n");

    }

    public static void main(String[] args) throws IOException
    {
    	genSeive();
        nextLine(br);
        int t=nextInt();
        while(t-- >0)

            solve();

        out.flush();
        out.close();

    }

        static int gcd(int a, int b) {

        // if b=0, a is the GCD
        if (b == 0)
            return a;

        // call the gcd() method recursively by
        // replacing a with b and b with
        // modulus(a,b) as long as b != 0
        else
            return gcd(b, a % b);
    }

    // lcm() method returns the LCM of a and b
    static int lcm(int a, int b, int gcdValue)
    {
        return Math.abs(a * b) / gcdValue;
    }

}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = Integer.parseInt(sc.nextLine());
        while (t-- > 0) {
            long result = 0;
            int n = sc.nextInt(), k = sc.nextInt();
            for (int i = 0; i < k; i++)
                result = (result * n) % 1000000007;
            System.out.println(result);
        }
        sc.close();
    }
}


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

public class Main

{
    class Pair<S extends Comparable<S>, T extends Comparable<T>> implements Comparable<Pair<S, T>> {
        S first;
        T second;

        Pair(S f, T s) {
            first = f;
            second = s;
        }

        @Override
        public int compareTo(Pair<S, T> o) {
            int t = first.compareTo(o.first);
            if (t == 0) return second.compareTo(o.second);
            return t;
        }

        @Override
        public int hashCode() {
            return (31 + first.hashCode()) * 31 + second.hashCode();
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Pair)) return false;
            if (o == this) return true;
            Pair p = (Pair) o;
            return first.equals(p.first) && second.equals(p.second);
        }

        @Override
        public String toString() {
            return "Pair{" + first + ", " + second + "}";
        }
    }
    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) throws java.lang.Exception
    {
        // try {
        //     System.setIn(new FileInputStream("input.txt"));
        //     System.setOut(new PrintStream(new FileOutputStream("output.txt")));
        // } catch (Exception e) {
        //     System.err.println("Error");
        // }

        FastReader sc = new FastReader();

        int t =sc.nextInt();
        PrintWriter out=new PrintWriter(System.out);
        while(t-->0){
            solve(sc,out);
        }
         out.close();
    }
    static void solve(FastReader sc,PrintWriter out) {
        long n = sc.nextInt();
        int k = sc.nextInt();
        long mod =1000000007;

        long res = n*(n-1);

        long temp=(long)Math.pow(2,k-1);
        temp=(temp*res)%mod;
        out.println(temp);

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

//import Number_theory.pair;

public class hacker49 {
	public static int r1=0;
	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;
        }
    }
	static class pair{
		private long cnt;
		private long[] fq;
		private long[] pref;
		pair(){
			fq=new long[41];
			pref=new long[41];
			cnt=(long)0;
		}
	}

	public static void main(String[] args) {
		OutputStream outputStream =System.out;
	    PrintWriter out =new PrintWriter(outputStream);
		FastReader s=new FastReader();
//        long[] a=new long[100000000];
		fac();
		int t=s.nextInt();
		while(t>0) {
			int n=s.nextInt();
			int k=s.nextInt();
			long d=1<<(k-1);
			long ans=((fac[n]*(d)))%mod;
			out.println(ans);
			t--;
		}
		out.close();

	}
	static long[] fac=new long[100001];
	static void fac() {
		fac[0]=1;
		for(int i=1;i<=100000;i++) {
			fac[i]=((fac[i-1])*i)%mod;
		}
	}
	static ArrayList<Integer>[] f=new ArrayList[2001];
	public static void init(int n) {

		for(int j=1;j<=n;j++) {
		for (int l=1; l<=Math.sqrt(j); l++)
        {
            if (j%l==0)
            {
                // If divisors are equal, print only one
                if (j/l == l) {
                    f[j].add(l);}

                else { // Otherwise print both
//                    System.out.print(i+" " + n/i + " " );
            f[j].add(l);
            f[j].add(j/l);
                }

            }
        }

		}

	}
	public static int rod_cutting_with_left_right_strategy(int[] a,int n) {
		int[] dp=new int[n+1];
		dp[1]=a[1];
		for(int i=2;i<=n;i++) {
			dp[i]=a[i];
			int left=1;
			int right=i-1;
			while(left<=right) {
				dp[i]=Math.max(dp[left]+dp[right],dp[i]);
			left++;
			right--;
			}

		}
		return dp[n];
	}
	public static long[] merge_sort(long[] A, int start, int end) {
		if (end > start) {
			int mid = (end + start) / 2;
			long[] v = merge_sort(A, start, mid);
			long[] o = merge_sort(A, mid + 1, end);
			return (merge(v, o));
		} else {
			long[] y = new long[1];
			y[0] = A[start];
			return y;
		}
	}
	public static long[] merge(long a[], long b[]) {
//		int count=0;
		long[] temp = new long[a.length + b.length];
		int m = a.length;
		int n = b.length;
		int i = 0;
		int j = 0;
		int c = 0;
		while (i < m && j < n) {
			if (a[i] < b[j]) {
				temp[c++] = a[i++];

			} else {
				temp[c++] = b[j++];
			}
		}
		while (i < m) {
			temp[c++] = a[i++];
		}
		while (j < n) {
			temp[c++] = b[j++];
		}
		return temp;
	}

	public static long[] merge_sort1(long[] A, int start, int end) {
		if (end > start) {
			int mid = (end + start) / 2;
			long[] v = merge_sort1(A, start, mid);
			long[] o = merge_sort1(A, mid + 1, end);
			return (merge1(v, o));
		} else {
			long[] y = new long[1];
			y[0] = A[start];
			return y;
		}
	}
	public static long[] merge1(long a[], long b[]) {
//		int count=0;
		long[] temp = new long[a.length + b.length];
		int m = a.length;
		int n = b.length;
		int i = 0;
		int j = 0;
		int c = 0;
		while (i < m && j < n) {
			if (a[i] > b[j]) {
				temp[c++] = a[i++];

			} else {
				temp[c++] = b[j++];
			}
		}
		while (i < m) {
			temp[c++] = a[i++];
		}
		while (j < n) {
			temp[c++] = b[j++];
		}
		return temp;
	}

	static long mod=1000000007;
	static class pair2{
		private long a;
		private int b;
		pair2(long a,int b){
			this.a=a;
			this.b=b;
		}
	}

}
//	for(int i=2;i<=100000;i++) {

//	}


//package q2;

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

public class Main{
public static void main(String args[]){
  MyScanner in = new MyScanner();
  MyWriter out = new MyWriter();
  int t = in.nextInt();	//number of test cases
  for(int i = 0; i < t; i++) {
	 int n = in.nextInt();		//size of array
	 int k = in.nextInt();//max number of digits in decimal
	 //exactly 0 in every digit
	 out.write(n*k % ((int)Math.pow(10, 9)+7)+"\n");

  }

  out.flush();
}

public static int gdc(int num1, int num2) {
	 while (num1 != num2) {
     	if(num1 > num2)
             num1 = num1 - num2;
         else
             num2 = num2 - num1;
     }
	 return num2;
}
public static int numDigits(int num) {
	int digits = 1;
	while(num >9) {
		num/=10;
		digits++;
	}
	return digits;
}

}

class MyWriter {
BufferedWriter bw;
public MyWriter() {
    bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
void write(String str){
  try{
    bw.write(str);
  }catch (IOException ex){
      ex.printStackTrace();
  }
}
void write(int i){
  try{
    bw.write(i+"");
  }catch (IOException ex){
      ex.printStackTrace();
  }
}
void write(long l){
  try{
    bw.write(l+"");
  }catch (IOException ex){
      ex.printStackTrace();
  }
}
void flush(){
  try{
    bw.flush();
  }catch(IOException ex){
    ex.printStackTrace();
  }

}

}

class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
       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.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public final class Main {
    public 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 (Exception e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        String nextLine(){
            String str="";
            try{
                str=br.readLine();
            }catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader in =new FastReader();
        int t=in.nextInt();
        while (t-->0){
            int n=in.nextInt();
            int k=in.nextInt();
            int ans= (int) Math.pow(n,k);
            System.out.println(ans);
        }
    }
}


/*
    JAI MATA DI
 */

import java.util.*;

import java.io.*;
import java.math.BigInteger;

public class Codechef {
	  static class FR{
			BufferedReader br;
			StringTokenizer st;
			public FR() {
				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;
		    }
		}
	 static int mod  = 1000000007;
	 static int gcd(int a, int b)
	  {
	     if (b == 0)
	        return a;
	     return gcd(b, a % b);
	  }
	 static long gcd(long a, long b)
	  {
	     if (b == 0)
	        return a;
	     return gcd(b, a % b);
	  }
	 static boolean[] prime(int num) {
			boolean[] bool = new boolean[num];

		      for (int i = 0; i< bool.length; i++) {
		         bool[i] = true;
		      }
		      for (int i = 2; i< Math.sqrt(num); i++) {
		         if(bool[i] == true) {
		            for(int j = (i*i); j<num; j = j+i) {
		               bool[j] = false;
		            }
		         }
		      }
		      if(num >= 0) {
		    	  bool[0] = false;
		    	  bool[1] = false;
		      }

		      return bool;
		}
	 static class Pair implements Comparable<Pair>{
	 		int skill;
	 		int players;
	 		Pair(int key , int value){
	 			this.skill = key;
	 			this.players = value;
	 		}
			@Override
			public int compareTo(Pair o) {
				return this.skill - o.skill;
			}
//			@Override
//			public int hashCode(){
//				return first + second;
//			}
	 	}

	 public static void main(String args[]) {
	 FR sc = new FR();
	 StringBuilder sb = new StringBuilder();
	 int tc = sc.nextInt();
	 while(tc-- > 0) {
		int n = sc.nextInt() ,  k = sc.nextInt();
		if(n ==1) {
			sb.append("2\n");
			continue;
		}

//		long ans = (long)(power(n, k ,mod)  )%mod;
		long ans  = 1;
		for(int i = 0 ; i<k ; i++) {
			ans = (ans*n)%mod;
		}

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

	 System.out.println(sb);
	 }

}


// 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));;
    	}
    }
}