#include <stdio.h>
#include <string.h>
#define NMAX 323
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, size;
char c1, c2, s[NMAX];
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++)
{
fscanf(fin, "%s", s);
size = strlen(s);
c1 = '0';
c2 = s[size-1];
if(size-1) c1 = s[size-2];
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;
}