#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll kq = 0,k,n,tam;
const ll mod = 1000;
struct matrix
{
ll mx[4][4];
}a,b;
matrix nhan(matrix a, matrix b, ll m)
{
matrix c;
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= 3; j++)
{
c.mx[i][j] = 0;
for(int k = 1; k <= 3; k++)
{
c.mx[i][j] = (c.mx[i][j] + a.mx[i][k]*b.mx[k][j])%mod;
}
}
}
return c;
}
matrix mu(matrix a, ll b)
{
if(b == 1)
return a;
matrix tam = mu(a,b/2);
tam = nhan(tam,tam,3);
if(b%2 == 1)
return nhan(tam,a,3);
return tam;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen("DAYSO.inp", "r", stdin);
freopen("DAYSO.out", "w", stdout);
cin >> k;
while(k--)
{
cin >> n;
a.mx[1][1] = 1, a.mx[1][2] = 0,a.mx[1][3] = 1;
b.mx[1][1] = 2;
b.mx[2][1] = -1;
b.mx[3][1] = 1;
b.mx[1][2] = 1;
b.mx[2][2] = 0;
b.mx[3][2] = 0;
b.mx[1][3] = 0;
b.mx[2][3] = 0;
b.mx[3][3] = 1;
b = mu(b,n);
a = nhan(a,b,1);
tam = a.mx[1][1] - a.mx[1][2];
tam*=tam;
tam%=10;
cout << tam << '\n';
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbGwga3EgPSAwLGssbix0YW07CmNvbnN0IGxsIG1vZCA9IDEwMDA7CnN0cnVjdCBtYXRyaXgKewogICAgbGwgbXhbNF1bNF07Cn1hLGI7Cm1hdHJpeCBuaGFuKG1hdHJpeCBhLCBtYXRyaXggYiwgbGwgbSkKewogICAgbWF0cml4IGM7CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG07IGkrKykKICAgIHsKICAgICAgICBmb3IoaW50IGogPSAxOyBqIDw9IDM7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGMubXhbaV1bal0gPSAwOwogICAgICAgICAgICBmb3IoaW50IGsgPSAxOyBrIDw9IDM7IGsrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYy5teFtpXVtqXSA9IChjLm14W2ldW2pdICsgYS5teFtpXVtrXSpiLm14W2tdW2pdKSVtb2Q7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gYzsKfQptYXRyaXggbXUobWF0cml4IGEsIGxsIGIpCnsKICAgIGlmKGIgPT0gMSkKICAgICAgICByZXR1cm4gYTsKICAgIG1hdHJpeCB0YW0gPSBtdShhLGIvMik7CiAgICB0YW0gPSBuaGFuKHRhbSx0YW0sMyk7CiAgICBpZihiJTIgPT0gMSkKICAgICAgICByZXR1cm4gbmhhbih0YW0sYSwzKTsKICAgIHJldHVybiB0YW07Cn0KaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIGZyZW9wZW4oIkRBWVNPLmlucCIsICJyIiwgc3RkaW4pOwogICAgZnJlb3BlbigiREFZU08ub3V0IiwgInciLCBzdGRvdXQpOwogICAgY2luID4+IGs7CiAgICB3aGlsZShrLS0pCiAgICB7CiAgICAgICAgY2luID4+IG47CiAgICAgICAgYS5teFsxXVsxXSA9IDEsIGEubXhbMV1bMl0gPSAwLGEubXhbMV1bM10gPSAxOwogICAgICAgIGIubXhbMV1bMV0gPSAyOwogICAgICAgIGIubXhbMl1bMV0gPSAtMTsKICAgICAgICBiLm14WzNdWzFdID0gMTsKICAgICAgICBiLm14WzFdWzJdID0gMTsKICAgICAgICBiLm14WzJdWzJdID0gMDsKICAgICAgICBiLm14WzNdWzJdID0gMDsKICAgICAgICBiLm14WzFdWzNdID0gMDsKICAgICAgICBiLm14WzJdWzNdID0gMDsKICAgICAgICBiLm14WzNdWzNdID0gMTsKICAgICAgICBiID0gbXUoYixuKTsKICAgICAgICBhID0gbmhhbihhLGIsMSk7CiAgICAgICAgdGFtID0gIGEubXhbMV1bMV0gLSBhLm14WzFdWzJdOwogICAgICAgIHRhbSo9dGFtOwogICAgICAgIHRhbSU9MTA7CiAgICAgICAgY291dCA8PCB0YW0gPDwgJ1xuJzsKICAgIH0KfQoK