#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
FILE *f=fopen("cifra.in","r");
ofstream f2("cifra.out");
int per[100]={1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0};
int main() {
int n;
char x;
int s=0;
fscanf(f,"%d",&n);
fscanf(f,"%c",&x);
while(n>0) {
int a=0;
s=0;
int i=0;
do {
fscanf(f,"%c",&x);
if(x!=10) {
a=a*10+(int)x-48;
a%=100;
i++;
}
} while(x!=10&&!feof(f));
for(int k=1;k<=100;k++) {
int tot=i/2+1;
if(k>a) tot--;
s+=tot*per[k-1];
}
s%=10;
f2<<s<<endl;
n--;
}
return n;
}