#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int t,s,r,p[10]={0,0,4,4,2,1,1,4,4,2},u[10][4]={0,0,0,0,1,0,0,0,6,2,4,8,1,3,9,7,6,4,0,0,5,0,0,0,6,0,0,0,1,7,9,3,6,2,4,8,1,9,0,0};
long n,c;
int main()
{
f>>t;
for(int y=1;y<=t;y++)
{
s=0;;
f>>n;
r=n%10;
n-=r;
c=n/10;
s=c*7;
s%=10;
for(c=1;c<=r;c++)
{
if(c==1)
{
s++;
s%=10;
continue;
}
if(c==5)
{
s+=5;
s%=10;
continue;
}
if(c==6)
{
s+=6;
s%=10;
continue;
}
s+=u[c][((n+c)%p[c])];
s%=10;
}
g<<s<<endl;
}
f.close();
g.close();
return 0;
}