#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
int main() {
cin.sync_with_stdio(false);
ifstream cin("cifra.in");
ofstream cout("cifra.out");
vector<int> ans(101);
for (int i = 1; i <= 100; i++) {
ans[i] = 1;
for (int j = 1; j <= i; j++) {
ans[i] = (ans[i] * i) % 10;
}
ans[i] = (ans[i] + ans[i - 1]) % 10;
}
int t;
cin >> t;
for (; t; t--) {
string s;
cin >> s;
if (s.size() == 1) {
cout << ans[s.back() - '0'] << '\n';
} else {
cout << ans[(s[s.size() - 2] - '0') * 10 + s[s.size() - 1] - '0'] << '\n';
}
}
return 0;
}