#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int n;
int t,k=0,i;
cin>>t;
while(t--)
{
cin>>n;
n=n%20;
k=n;
for(i=1;i<n;i++)
{
k=(k*n)%10;
}
cout<<k<<endl;
}
return 0;
}