#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double
 
 
const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;
 

 
 
//_ ***************************** START Below *******************************
 
 
int power(int a, int n, int mod=M) {
    a %= mod;
    int res = 1;
    while (n) {
        if (n & 1) res = (res*a)%mod;
        a = (a*a)%mod;
        n >>= 1;
    }
    return res;
}

int binPower(int a, int n, int mod=M){
	if(n==0) return 1;
	
	int res = binPower(a, n/2)%mod;
	
	if(n & 1) return ((res * res)%mod * a)%mod;
	return (res * res )%mod;
}
 

 
void solve() {
    
    
    int a, n;
    cin>>a >> n;

    cout << power(a, n) << " " << binPower(a, n) << endl;
 
 
}
 
 
 
 
 
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
 
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
 
    return 0;
}