#include<cstdio>
#include<cstring>
long y,i,n,m,a[200],t;
char s[200];
int put(long a, long b, bool ok){
if(b==0)
if(ok==1)return 0;
else return 1;
//if(b==1)return a;
if(b % 2==0)return put(a*a,b/2,ok);
return a*put(a,b-1,ok);
}
int cf(long x){
switch (x % 10){
case 0:return 0;
case 1:return 1;
case 2:if(x>=4)return ((6+put(2,x % 4,1))% 10);
else return (put(2,x,0)% 10);
case 3:if(x>=4)return ((1+put(3,x % 4,1))% 10);
else return (put(3,x,0)% 10);
case 4:if(x>=2)return ((6+put(4,x % 2,1))% 10);
else return (put(4,x,0)% 10);
case 5:return 5;
case 6:return 6;
case 7:if(x>=4)return ((1+put(7,x % 4,1))% 10);
else return (put(7,x,0)% 10);
case 8:if(x>=4)return ((6+put(8,x % 4,1))% 10);
else return (put(8,x,0)% 10);
case 9:if(x>=2)return ((1+put(9,x % 2,1))% 10);
else return (put(9,x,0)% 10);
}
return 0;
}
int main(){
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
m=0;a[0]=5;
for(i=3;i<=102;i++)
a[++m]=(a[m-1]+cf(i))% 10;
a[0]=a[m];
scanf("%ld\n",&t);
while(t){
fgets(s,200,stdin);
y=strlen(s)-2;
if(y==0)n=s[y]-'0';
else n=(s[y-1]-'0')*10+(s[y]-'0');;
if(n==1)printf("1\n");
else if(n==2)printf("5\n");
else printf("%ld\n",a[(n-2)% m]);
t--;
}
fclose(stdin);
fclose(stdout);
return 0;
}