#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];
values[i - 1] %= 10;
// printf("%d -> %d \n", i-1, values[i-1]);
}
values[99] %= 10;
// return 0;
int tests;
scanf("%d", &tests);
while(tests--) {
scanf("%s", number);
int length = strlen(number);
int value = length > 2 ? atoi(number + strlen(number) - 2) : atoi(number);
// printf("Value: %d\n", value);
printf("%d\n", values[value]);
}
return 0;
}