#include <fstream>
#include <string.h>
#include <math.h>
using namespace std;
ifstream f1("cifra.in");
ofstream f2("cifra.out");
int main(void)
{
const short int uc[20]={1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9,0};
const short int sume[20]={0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4};
const short int s=4;
string n;
short int smnf, rasp=0, aux;
int i, t, asdf;
f1>>t;
for (asdf=1; asdf<=t; asdf++)
{
rasp=0;
f1>>n;
n="0"+n;
//f2<<n[n.length()-2];
smnf=((int)n[n.length()-2]-48)*10+(int)n[n.length()-1]-48;
rasp=floor(smnf/20)*s;
rasp+=sume[smnf%20];
f2<<rasp%10<<endl;
}
f1.close();
f2.close();
return 0;
}