// Problem: E. Arena
// Contest: Codeforces - Educational Codeforces Round 116 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1606/problem/E
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)

// Problem: D. Frog Traveler
// Contest: Codeforces - Codeforces Round #751 (Div. 2)
// URL: https://codeforces.com/contest/1602/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;

/**
 * zxz
 * problem link:
 **/
public class Main {

    //put some data here

    /**
     * do some clean action before next testcase
     */
    private void clear() {

    }

	void cal(int n, int x){
		long t = pow_mod(x,n,mod);
		ans = (ans + t) % mod;
	}
	long [][] c;
	long ans = 0;
	long mod = 998244353L;
	long [][] dp;
	long dfs(int n, int x){
		if(dp[n][x] >= 0){
			return dp[n][x];
		}
		// System.out.println(n + "-" + x);
		long res = pow_mod(min(n-1, x),n, mod);
		// System.out.println("all die" + res);
		if(x >= n){
			for(int i = 2; i <= n; i++){
// System.out.println(i + "  " + pow_mod(n-1,x - i,mod) * Cnm(n,i));
				res += pow_mod(n-1,n - i,mod)* c[n][i] * dfs(i, x - n + 1) % mod;
				res %= mod;

			}
		}
		dp[n][x] = res;
		// System.out.println(n + " " + x + " " + res);
		return res;
	}

    private void solve() throws Exception {
        rf();
        int n = ri();
        int x = ri();
		dp = new long[n + 1][x + 1];
		for(int i = 0; i <= n; i++){
			Arrays.fill(dp[i], -1);
		}

		c = new long[n + 1][n + 1];
		c[0][0]= 1;
		for(int i = 1; i <= n; i++){
			c[i][0] = 1;
			// System.out.print(c[i][0] + " ");
			for(int j = 1; j <= i; j++){
				c[i][j] = (c[i - 1][j] + c[i-1][j-1]) % mod ;
				// System.out.print(c[i][j] + " ");
			}
			// System.out.println();
		}

		// dfs(n,x);
		addAns(dfs(n,x));
    }

    private void run() throws Exception {

        int T = 1;

        while (T-- > 0) {
            solve();
            if (T != 0) {
                clear();
            }
        }
        printAns();
    }

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

    StringBuilder sb = new StringBuilder();
    BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer strT;

	private void addAns(int a){
		sb.append(a + "\n");
	}

	private void addAns(long a){
		sb.append(a + "\n");
	}

	private void addAns(String s){
		sb.append(s + "\n");
	}

    private void rf() throws IOException {
        strT = new StringTokenizer(infile.readLine());
    }

    private int ri() {
        return Integer.parseInt(strT.nextToken());
    }

    private long rl() {
        return Long.parseLong(strT.nextToken());
    }

	private char [] rs2c(){
		return strT.nextToken().toCharArray();
	}

	private String rs(){
		return strT.nextToken();
	}

    private void printAns() {
        System.out.println(sb);
    }

    private int[] readArr(int N) throws Exception {
        int[] arr = new int[N];
        rf();
        for (int i = 0; i < N; i++) {
            arr[i] = Integer.parseInt(strT.nextToken());
        }
        return arr;
    }

    private void print(int[] arr) {
        //for debugging only
        for (int x : arr) {
            System.out.print(x + " ");
        }
        System.out.println();
    }

    private void print(long[] arr) {
        //for debugging only
        for (long x : arr) {
            System.out.print(x + " ");
        }
        System.out.println();
    }

    private long[] readArr2(int N) throws Exception {
        long[] arr = new long[N];
        strT = new StringTokenizer(infile.readLine());
        for (int i = 0; i < N; i++) {
            arr[i] = Long.parseLong(strT.nextToken());
        }
        return arr;
    }

    private boolean isPrime(long n) {
        if (n < 2) {
            return false;
        }
        if (n == 2 || n == 3) {
            return true;
        }
        if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

    private long gcd(long a, long b) {
        if (a > b) {
            a = (a + b) - (b = a);
        }
        if (a == 0L) {
            return b;
        }
        return gcd(b % a, a);
    }

    private int gcd(int a, int b) {
        if (a > b) {
            a = (a + b) - (b = a);
        }
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    private double pow(double x, long N) {
        double ans = 1.0;
        // 贡献的初始值为 x
        double x_contribute = x;
        // 在对 N 进行二进制拆分的同时计算答案
        while (N > 0) {
            if (N % 2 == 1) {
                // 如果 N 二进制表示的最低位为 1，那么需要计入贡献
                ans *= x_contribute;
            }
            // 将贡献不断地平方
            x_contribute *= x_contribute;
            // 舍弃 N 二进制表示的最低位，这样我们每次只要判断最低位即可
            N /= 2;
        }
        return ans;
    }

    long pow_mod(long x, long i, long mod){
	    if(i == 0){
	        return 1;
	    }
	    long temp = pow_mod(x, i >> 1, mod);
	    temp = temp * temp % mod;
	    if((i & 1 )!= 0){
	        temp = temp * x % mod;
	    }
	    return temp;
	}

}


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

public class Div21606E {

	public static long MOD = 998244353;
	public static long[] factorial = new long[501];
	public static long[] inverse_fac = new long[501];

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());

		int n = Integer.parseInt(st.nextToken());
		int x = Integer.parseInt(st.nextToken());

		factorial[0] = 1;
		for (long i = 1; i <= 500; i++)
		    factorial[(int) i] = (factorial[(int) (i - 1)] * i) % MOD;

		inverse_fac[1] = binpow(1, MOD-2, MOD);
		for(int i = 2; i <= 500; ++i)
			inverse_fac[i] = binpow(factorial[i], MOD-2, MOD);

		long[][] dp = new long[n][x];

		Arrays.fill(dp[0], 0);

		for(int i = 1; i < n; i++) {

			for(int j = 0; j < x; j++) {

				if(j < i)
					dp[i][j] = binpow(j+1, i+1, MOD);
				else {

					dp[i][j] += dp[i][j-1];

					for(int k = i; k > 0; k--) {

						if(j-i == 0)
							dp[i][j] = (dp[i][j] + binpow(i, i-k, MOD) * dp[k][j-i] * binomial_coefficient(i+1, k+1)) % MOD;
						else {

							long min = (dp[k][j-i] - dp[k][-1+j-i]) % MOD;

							if(min < 0)
								min += MOD;

							dp[i][j] = (dp[i][j] + binpow(i, i-k, MOD) * min * binomial_coefficient(i+1, k+1)) % MOD;

						}

					}
				}

			}

		}

		/*for(int i = 0; i < x; i++) {
			for(int j = 0; j < n; j++)
				System.out.print(dp[j][i] + " ");
		System.out.println();
		}*/

		System.out.println(dp[n-1][x-1]);

	}

	static long binpow(long a, long b, long m) {

	    a %= m;

	    long res = 1;

	    while (b > 0) {

	        if ((b & 1) == 1)
	            res = res * a % m;

	        a = a * a % m;
	        b >>= 1;

	    }

	    return res;

	}

	static long binomial_coefficient(int n, int k) {

		if(n == k)
			return 1;

		return (factorial[n] * inverse_fac[k] % MOD) * inverse_fac[n - k] % MOD;

	}

}


import java.util.Scanner;
public class Q1606E {

	final static long N = 998244353;
	static long C[][] = new long[501][501];
	static long ans[][] = new long[501][501];

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int x = s.nextInt();
		for(int i=2;i<=n;i++)
		{
			for(int j=1;j<=x;j++)
			{
				System.out.printf("%9d ",calculate(i,j));
			}
			System.out.println("");
		}
		//System.out.println(calculate(n,x));
	}

	public static long ncr(int n, int r)
	{
		if(C[n][r]!=0) return C[n][r];
		else
		{
			if(r==0||n==r)
			{
				C[n][r] = 1;
				return 1;
			}
			else
			{
				C[n][r] = (ncr(n-1,r-1)+ncr(n-1,r))%N;
				return C[n][r];
			}
		}
	}

	public static long calculate(int n, int x)
	{
		if(ans[n][x]!=0) return ans[n][x];
		else
		{
			if(n==2)
			{
				ans[n][x] = x;
				return x;
			}
			if(x<=n-1)
			{
				long j = 1;
				for(int k=1; k<=n; k++)
				{
					j*=x;
					j%=N;
				}
				ans[n][x] = j;
				return j;
			}
			for(int i=2; i<=n; i++)
			{
				long j = (ncr(n,i)*calculate(i,x-n+1))%N;
				for(int k=1;k<=n-i;k++)
				{
					j*=(n-1);
					j%=N;
				}
				ans[n][x] += j;
				ans[n][x] %=N;
			}
			long j=1;
			for(int k=1;k<=n;k++)
			{
				j*=(n-1);
				j%=N;
			}
			ans[n][x] += j;
			ans[n][x] %= N;
			return ans[n][x];
		}
	}
}


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

public class Main {
	static PrintWriter out;
	static Reader in;
	public static void main(String[] args) throws Exception {
		input_output();
		Main solver = new Main();
		solver.solve();
		out.close();

		out.flush();
	}

	static int INF = (int)1e9;
	static int MAXN = 500;
	static int MOD = 998244353;
	static int q, t, m, n, k;

	static long[][] dp, remove, c;

	void solve() throws Exception {
		n = in.nextInt();
		k = in.nextInt();

		dp = new long[k+1][n];
		for (int i = 0; i <= k; i++)
			for (int j = 0; j < n; j++)
				dp[i][j] = -1;

		remove = new long[n][n]; // remove[left][removed] = left^removed;
		for (int i = 1; i < n; i++) remove[i][0] = 1;
		remove[0][0] = 1;
		for (int i = 1; i < n; i++) {
			for (int j = 1; j <= i; j++) {
				remove[i][j] = (remove[i][j-1] * i) % MOD;
			}
		}

		c = new long[MAXN+1][MAXN+1];
		c[0][0] = 1;
		c[1][0] = 1;
		c[1][1] = 1;
		for (int i = 1; i <= MAXN; i++) {
			c[i][0] = 1;
			for (int j = 1; j <= i; j++) {
				c[i][j] = (c[i-1][j]+c[i-1][j-1]) % MOD;
			}
		}

		long ans = 0;
		for (int i = 1; i <= k; i++) rec(i, n-1);

		for (int i = 1; i <= k; i++) {
			ans = (ans + dp[i][n-1]) % MOD;
		}

		ans = (ans * n) % MOD;
		long all = 1;
		for (int i = 1; i <= n; i++) all = (all * k) % MOD;
		ans = (all-ans+MOD) % MOD;
		out.println(ans);
	}

	static long rec(int val, int left) {
		if (val <= 0) return 0;
		if (dp[val][left] != -1) return dp[val][left];

		if (left == 0) return dp[val][left] = 1;
		long res = 0;
		for (int i = 0; i <= left; i++) {
			res += (rec(val-left, left-i) * ((remove[left][i] * c[left][i]) % MOD)) % MOD;
		}

		return dp[val][left] = res;
	}

	static class Reader {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public Reader() {
			this(System.in);
		}

		public Reader(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();

			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

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

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
	static void input_output() throws IOException {
		File f = new File("in.txt");
		if (f.exists() && !f.isDirectory()) {
			in = new Reader(new FileInputStream("in.txt"));
		} else in = new Reader();
		f = new File("out.txt");
		if (f.exists() && !f.isDirectory()) {
			out = new PrintWriter(new File("out.txt"));
		} else out = new PrintWriter(System.out);
	}
}


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

public class E1646 {
    static final int MAX = (int) 1e6 + 1;

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

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int[] lp = new int[MAX];
        for (int i = 2; i < lp.length; i++) {
            if (lp[i] == 0) {
                for (int j = i; j < lp.length; j += i) {
                    if (lp[j] == 0) {
                        lp[j] = i;
                    }
                }
            }
        }
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] val = new int[25];
        HashSet<Long> hs = new HashSet<>();
        for (int i = 1; i < val.length; i++) {
            for (int j = 1; j <= m; j++) {
                hs.add(1L * j * i);
            }
            val[i] = hs.size();
        }
        long ans = 1;
        for (int i = 2; i <= n; i++) {
            int x = i;
            int curP = lp[x];
            int cnt = 0;
            ArrayList<Integer> factors = new ArrayList<>();
            while (x > 1) {
                if (lp[x] == curP) {
                    cnt++;
                } else {
                    factors.add(cnt);
                    curP = lp[x];
                    cnt = 1;
                }
                x /= lp[x];
            }
            factors.add(cnt);
//            System.out.println(factors);
            int gcd = 0;
            for (int f : factors) {
                gcd = gcd(f, gcd);
            }
            ans += val[gcd];
        }
        pw.println(ans);
        pw.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

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

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        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 double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(next());
            }
            return arr;
        }

    }
}


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

public class C774E {

    static StringBuffer ans1 = new StringBuffer("");
    static FastScanner sc = new FastScanner();
    static PrintWriter printWriter = new PrintWriter(System.out);

    public static void solve(int n, int m) {
        int depth = 0, temp = n;
        while(temp > 1) {
            temp /= 2;
            depth++;
        }
        int[] dp = new int[depth + 1];
        boolean[] visited = new boolean[m * depth + 1];
        int size = 0;
        for (int i = 1; i <= depth; i++) {
            for(int j = 1; j <= m; j++) {
                if(!visited[i * j]) size++;
                visited[i * j] = true;
            }
            dp[i] = size;
            printWriter.println(i + " " + dp[i]);
        }
        long res = 1;
        boolean[] used = new boolean[n + 1];
        for(int i = 2; i <= n; i++) {
            if(used[i]) continue;
            int k = i, count = 0;
            while(k <= n) {
                used[k] = true;
                count++;
                if(k * 1L * i != k * i) break;
                k *= i;
            }
            res += dp[count];
        }
        printWriter.println(res);
    }

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        solve(n, m);
        printWriter.flush();
    }

    /*****************************************************************
     ******************** DO NOT READ AFTER THIS LINE *****************
     *****************************************************************/
    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[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] read2dArray(int n, int m) {
            int arr[][] = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = nextInt();
                }
            }
            return arr;
        }

        ArrayList<Integer> readArrayList(int n) {
            ArrayList<Integer> arr = new ArrayList<Integer>();
            for (int i = 0; i < n; i++) {
                int a = nextInt();
                arr.add(a);
            }
            return arr;
        }

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


//package com.example.practice.codeforces.sc2200;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

//E. Power Board
public class Solution2 {
    final static int D = 20;
    final static int M = 1 << D;
    final static boolean[] nonPrime = new boolean[M+1];
    final static ArrayList<Integer> primes = new ArrayList<>();
    static {
        for (int i=2, k=(int)Math.sqrt(M); i<=k; ++i){
            if (!nonPrime[i]){
                primes.add(i);
                int t = i*i;
                while(t <= M){
                    nonPrime[t] = true;
                    t += i;
                }
            }
        }
    }
    public static void main (String [] args) throws IOException {
        // Use BufferedReader rather than RandomAccessFile; it's much faster
        final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        // input file name goes above
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("inflate.out")));

        StringTokenizer st = new StringTokenizer(input.readLine());
        int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken());
        System.out.println(calc(n, m));
        //out.close();       // close the output file
    }

    private static long calc(final int n, final int m) {
        final int[] rd = new int[D+1];
        boolean[] seen = new boolean[D*m+1];
        for (int i=1;i<=D;++i){
            int t = 0;
            for (int j=i*i,k=i;k<=m;++k,j+=i){
                if(!seen[j]){
                    t++;
                    seen[j] = true;
                }
            }
            rd[i] = t;
        }
        long res = 1;
        for (int i=2;i<=n;++i){
            int t = i, gcd = 0;
            for (int a : primes){
                int c = 0;
                while (t%a == 0){
                    t /= a;
                    c++;
                }
                gcd = GCD(c, gcd);
                if (t==1)break;
                if (!nonPrime[t]){
                    gcd = 1;
                    break;
                }
            }
            res += rd[gcd];
        }
        return res;
    }

    private static int GCD(int x, int y){
        if(x>y)return GCD(y, x);
        if (x==0)return y;
        return GCD(y%x, x);
    }
}


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

public class Contest1646E
{
    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        String next() { // reads in the next string
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() { // reads in the next int
            return Integer.parseInt(next());
        }
        public long nextLong() { // reads in the next long
            return Long.parseLong(next());
        }
        public double nextDouble() { // reads in the next double
            return Double.parseDouble(next());
            }
        }
    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static long mod = 1000000007;
    public static void main(String[] args)
    {
    	int n = r.nextInt();
    	int m = r.nextInt();
    	int[] count = new int[n+5];
    	boolean[] seen = new boolean[n+5];
    	for (int i = 2; i <= n; i ++)
    	{
    		long j = i;
    		if (!seen[(int)j])
    		{
    			while (j <= n)
    			{
    				seen[(int)j] = true;
    				j *= i;
    				count[i] ++;
    			}
    		}
    	}
    	long ans = 1;
    	long[] hi = new long[22];
    	hi[0] = 0;
    	hi[1] = m;
    	for (int i = 2; i <= 20; i ++)
    	{
    		hi[i] = hi[i-1] + m - ((i-1)*m)/i;
    	}
    	for (int x = 2; x <= n; x ++)
    	{
    		ans += hi[count[x]];
    	}
    	pw.println(ans);
    	/*
    	1 1 1 1 1
    	2 4 8 16 32
    	3 9 27 81 243
    	4 16 64 256 1024
    	 */
        pw.close();
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
import java.util.*;

public class Main {
    private final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    private StringTokenizer st;
    private final Long MOD = 1000000007L;
    private final String endl = "\n";

    boolean isConsonant(char c) {
        return !isVowel(c);
    }

    boolean isVowel(char c) {
        return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
    }

    // IO UTILS

    void log(Object... args) {
        if (!TESTING) return;
        for (Object s : args) System.out.print(s.toString() + " ");
        System.out.println();
    }

    String line() throws IOException {
        return in.readLine().trim();
    }

    StringTokenizer tokens() throws IOException {
        return new StringTokenizer(line());
    }

    long l(String s) {
        return Long.parseLong(s);
    }

    long rl() throws IOException {
        return l(line());
    }

    long[] rla(int n) throws IOException {
        long[] arr = new long[n];
        st = tokens();
        for (int i = 0; i < n; i++)
            arr[i] = l(st.nextToken());
        return arr;
    }

    int i(String s) {
        return Integer.parseInt(s);
    }

    int ri() throws IOException {
        return i(line());
    }

    int[] ria(int n) throws IOException {
        int[] arr = new int[n];
        st = tokens();
        for (int i = 0; i < n; i++)
            arr[i] = i(st.nextToken());
        return arr;
    }

    String rs() throws IOException {
        return line();
    }

    String[] rsa(int n) throws IOException {
        String[] s = new String[n];
        st = tokens();
        for (int i = 0; i < n; i++)
            s[i] = st.nextToken();
        return s;
    }

    double d(String s) {
        return Double.parseDouble(s);
    }

    double rd() throws IOException {
        return d(line());
    }

    double[] rda(int n) throws IOException {
        double[] arr = new double[n];
        st = tokens();
        for (int i = 0; i < n; i++) {
            arr[i] = d(st.nextToken());
        }
        return arr;
    }
    // IO UTILS END

    // MATH UTILS

    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long lcm(long a, long b) {
        long g = gcd(a, b);
        return (a / g) * b; // directly multiply a and b can overflow
    }

    public long modInv(long a, long MOD) {
        return new BigInteger(a + "").modPow(new BigInteger((MOD - 2) + ""), new BigInteger(MOD + "")).longValue();
    }

    public long modPro(long a, long b, long MOD) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }

    private long factorialMod(int n, long MOD) {
        long pro = 1;
        for (long i = 1; i <= n; i++) {
            pro = pro * i;
            pro %= MOD;
        }
        return pro;
    }

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

    static void ruffleSort(long[] a) {
        // ruffle
        int n = a.length;
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int oi = r.nextInt(n);
            long temp = a[i];
            a[i] = a[oi];
            a[oi] = temp;
        }
        Arrays.sort(a);
    }

    boolean[] sieveOfEratosthenes(int n) {
        boolean[] prime = new boolean[n + 1];
        for (int i = 0; i < n; i++)
            prime[i] = true;
        prime[0] = false;
        prime[1] = false;
        for (int i = 4; i <= n; i += 2) {
            prime[i] = false;
        }
        for (int p = 3; p * p <= n; p += 2) {
            // If prime[p] is not changed, then it is a prime
            if (prime[p]) {
                // Update all multiples of p
                for (int i = p * p; i <= n; i += p)
                    prime[i] = false;
            }
        }
        return prime;
    }

    // MATH UTILS END
    private final boolean TESTING = false;

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

    private void solve() throws Exception {
        int testCases = 1;
//        testCases = Integer.parseInt(in.readLine().trim());
        preProcess();
        for (int i = 1; i <= testCases; i++) {
            solveTestCase(i);
        }
        out.flush();
        out.close();
    }

    void preProcess() {

    }

    private void solveTestCase(int testCaseNumber) throws Exception {
        int[] arr = ria(2);
        int n = arr[0];
        int m = arr[1];
        int log = 0;
        int two = 2;
        while (true) {
            if (two > n)
                break;
            two *= 2;
            log++;
        }

//999439867182
        boolean set[] = new boolean[log * n + 1];
        long hash[] = new long[log + 1];
        int count = 0;
        for (int i = 1; i <= log; i++) {
            for (int j = 1; j <= m; j++) {
                if (!set[i*j]) {
                    set[i*j] = true;
                    count += 1;
                }
            }
            hash[i] = count;
        }
//        System.out.println(set + endl + Arrays.toString(hash));

        long ans = 0;
        boolean[] done = new boolean[n + 1];
        for (int i = 2; i <= n; i++) {
            if (!done[i]) {

                long pow = 1;
                done[i] = true;
                long temp = i;
                while (true) {
                    temp *= i;
                    if (temp > n)
                        break;
                    done[(int) temp] = true;
                    pow++;

                }
//								System.out.println( i+ " " + pow+ " " + hash[(int)pow]);
                ans += hash[(int) pow];

            }
        }

        out.write(ans + 1 + endl);

    }

}


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

}