#include <stdio.h>
FILE *fin, *fout;
int t, arr[20] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4}, temp, ans;
char c1, c2, c3;
bool f;
int main()
{
fin = fopen("cifra.in", "r");
fout = fopen("cifra.out", "w");
fscanf(fin, "%d", &t);
for(int i = 0; i< t; i++)
{
c1 = '0';
fscanf(fin, "%c", &c2);
if(i == 0)
{
fscanf(fin, "%c", &c2);
}
f = 0;
while(1)
{
fscanf(fin, "%c", &c3);
if(c3 == '\n')
{
break;
}
c1 = c2;
c2 = c3;
}
temp = (c1-'0')*10 + (c2-'0');
ans = (temp/20)*4 + arr[temp%20];
fprintf(fout, "%d\n",ans%10);
}
fclose(fin);
fclose(fout);
return 0;
}