##1060
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n;
double x;
cin>>t;
while(t--){
scanf("%d",&n);
x=n*log10(n);
x=x-floor(x);
printf("%d\n",(int)pow(10,x));
}
}
##1060
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n;
double x;
cin>>t;
while(t--){
scanf("%d",&n);
x=n*log10(n);
x=x-floor(x);
printf("%d\n",(int)pow(10,x));
}
}