#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int mat[11][11]={{},{0,1,1,1,1},{0,2,4,8,6},{0,3,9,7,1},{0,4,6,4,6},{0,5,5,5,5},{0,6,6,6,6},{0,7,9,3,1},{0,8,4,2,6},{0,9,1,9,1}},i,j,u;
char s[101];
int t,x,sum;
int main ()
{
f>>t;
f.get();
for (i=1;i<=t;i++)
{
f.get(s,100);
x=strlen(s);
if (x>1)
sum+=mat[s[x-1]-'0'][((s[x-2]-'0')*10+s[x-1]-'0')%4==0?4:((s[x-2]-'0')*10+s[x-1]-'0')%4];
else
sum+=mat[s[x-1]-'0'][(s[x-1]-'0')%4==0?4:(s[x-1]-'0')%4];
g<<sum%10;
g<<endl;
f.get();
}
}