#include <cstdio>
#include <cstring>
#include <cstdlib>
int main() {
freopen("cifra.in", "r", stdin);
freopen("cifra.out", "w", stdin);
char number[102];
int matrix[10][4] = {{0, 0, 0, 0},
{1, 1, 1, 1},
{6, 2, 4, 8},
{1, 3, 9, 7},
{6, 4, 6, 4},
{5, 5, 5, 5},
{6, 6, 6, 6},
{1, 7, 9, 3},
{6, 8, 4, 2},
{1, 9, 1, 9}
};
int values[100];
values[0] = 0;
for(int i = 1; i < 100; i++) {
values[i] = values[i - 1] + matrix[i % 10][i % 4];
// printf("%d -> %d \n", i, values[i]);
}
int tests;
scanf("%d", &tests);
while(tests--) {
scanf("%s", number);
int length = strlen(number);
int value;
if(length > 2) {
value = atoi(number + strlen(number) - 2);
} else {
value = atoi(number);
}
// printf("Value: %d\n", value);
printf("%d\n", values[value] % 10);
}
return 0;
}