#include<stdio.h>
int t,m,a[10][5]={{0,0,0,0,0},
{1,1,1,1,1},
{1,2,4,8,6},
{1,3,9,7,1},
{1,4,6,4,6},
{1,5,5,5,5},
{1,6,6,6,6},
{1,7,9,3,1},
{1,8,4,2,6},
{1,9,1,9,1}};
char cifra[50000];
long n,i;
int cif(int n)
{if(n<t) return cifra[n];
int c=cifra[t];
for(i=t+1;i<=n;i++)
{c=c+a[i%10][i%4==0 ? 4:i%4];
c=c%10;
cifra[i]=c;}
if(n<50000)t=n;
return c;}
int main()
{freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
scanf("%d",&m);
t=1;
cifra[0]=0;
cifra[1]=1;
for(int j=1;j<=m;j++)
{scanf("%ld",&n);
printf("%d\n",cif(n));}
fclose(stdout);
return 0;}