for _ in range(int(input())): n=int(input()) ans=0 res=1 for i in range(10): x=n-i if x>=0: ans+=res res*=x res%=10 print(ans%10)