#include<stdio.h>
int main(){
int n,s,t,i,m;
while(scanf("%d",&t)!=EOF){
while(t--){
s=1;
scanf("%d",&n);
m=(n-1)%4;
n=n%10;
for(i=0;i<=m;++i){
s*=n;
}
printf("%d",s%10);
printf("\n");
}
}
return 0;
}
int main(){
int n,s,t,i,m;
while(scanf("%d",&t)!=EOF){
while(t--){
s=1;
scanf("%d",&n);
m=(n-1)%4;
n=n%10;
for(i=0;i<=m;++i){
s*=n;
}
printf("%d",s%10);
printf("\n");
}
}
return 0;
}