#include using namespace std; using ll = long long; int solve(ll n){ if(n <= 1) return 2; int d = 0; ll aux = 1; for(int i = n;i >= n - 5 && i >= 0;--i){ d = (d + aux) % 10; aux = aux * n % 10; --n; } return d; } int main(){ int T; cin >> T; ll N; while(T--){ cin >> N; cout << solve(N) << '\n'; } return 0; }