#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main() {
string line;
int n,a,b,c;
int s[101];
int x[11][5] = {{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}};
int y[] = {1,1,4,4,2,1,1,4,4,2};
ifstream myfile("cifra.in");
ofstream outfile("cifra.out");
s[0] = 0;
c = 0;
getline(myfile,line);
n = atoi(line.c_str());
for (int i = 1; i<=n; i++) {
getline(myfile,line);
if(line.length()>2)
a = atoi(line.substr(line.length()-2).c_str());
else
a = atoi(line.c_str());
while(c <= a) {
c++;
b = c % 10;
s[c] = (s[c-1] + x[b][c%y[b]])%10;
}
outfile<<s[a]<<"\n";
}
myfile.close();
outfile.close();
return 0;
}