//模幂运算,而且求个位,一直求10的模
# include
# include
# include
using namespace std;
__int64 Pow(__int64 m,__int64 n)
{
__int64 p=1;
while(n)
{
if(n%2)
p=p*m%10;
n/=2;
m=m*m%10;
}
return p%10;
}
int main()
{
int t;
__int64 n,m;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%I64d",&n);
m=n;
m%=10;//求个位的n次取模
if(m==0)
printf("0
");
else
printf("%I64d
",Pow(m,n));
}
}
return 0;
}