#include<cstdio>
#include<cstring>
int v[]={0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9};
int i,j,n,m,k,t,A[102];
char s[101],c;
unsigned long divide()
{ int i;
unsigned long R=0;
for (i=A[0];i;i--)
{ A[i]=(R=10*R+A[i])/20;
R%=20;
}
while (!A[A[0]] && A[0]>1) A[0]--;
return R;
}
int main ()
{
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
scanf("%d%c",&t,&c);
for(i=1;i<=19;i++)
v[i]=v[i-1]+v[i];
for(i=1;i<=t;i++)
{
gets(s);
A[0]=strlen(s);
for(j=1;j<=n;j++)
A[j]=s[A[0]-j]-'0';
int x=divide();
printf("%d\n",(2*A[1]+v[i])%10);
}
return 0;
}