直接套快速幂模板
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
int powermod(int a,int b,int c){int ans=1;a = a % c;while(b>0){if(b%2) ans = (ans * a) %c;b = b/2;a = (a * a)%c;}return ans;
}
int main(){int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);printf("%d\n",powermod(n,n,10));}return 0;
}