#include <bits/stdc++.h>
    #define IOS         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define int      long long int
    #define rep(i,n) for(int i=0;i<n;i++)
    #define rep1(i,n) for(int i=1;i<=n;i++)
    #define gcd(a,b)       __gcd(a,b)
    #define lcm(a,b)	(a*b)/gcd(a,b)
    #define mem1(a)        memset(a,-1,sizeof(a))
    #define mem0(a)        memset(a,0,sizeof(a))
    #define vint        vector<int>
    #define pb            push_back
    #define pf            push_front
    #define ppb         pop_back
    #define all(v)      v.begin(),v.end()
    #define pii         pair<int,int>
    #define pic         pair<int,char>
    #define fr            first
    #define sc         second
    #define mp         make_pair
    #define sz(a)       a.size()
    #define inarr(a,n)	for(int i=0;i<n;i++)cin>>a[i];
    #define showarr(a,n)	for(int i=0;i<n;i++)cout<<a[i]<<" ";
 
    #define PI   		3.1415926535897
    #define time_passed	1.0 * clock() / CLOCKS_PER_SEC
    using namespace std;
    /*#####################################################*/
    int N=1e9+7;
    int pw(int a,int b)
    {
        if(b==0)return 1;
        
        if(b%2==0)
        {
            int ans=pw(a,b/2);
            return (ans*ans)%N;
        }
        if(b%2==1)
        {
            int ans=(pw(a,(b-1)/2))%N;
            return (a%N *ans%N*ans%N)%N;
        }
    }
    /*##################################################*/
    void love_for_infinity()
    {
       int n,k;
       cin>>n>>k;
       cout<<pw(n,k);
       
    }
    signed main()
    {    IOS
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        #ifdef SIEVE
        sieve();
        #endif
        #ifdef NCR
        init();
        #endif
        int t;t=1; cin>>t;
 
 
        while(t--){love_for_infinity();cout<<endl;}
        return 0;
    }