#include<bits/stdc++.h>
using namespace std;
const int maxi = 5000;
const int MaskMax = 1<<9;
int dp[MaskMax];
int dx[] = {1 , -1 , 0 , 0};
int dy[] = {0 , 0 , 1 , -1};
int mod = 10007;
int onefloar(int mask)
{
if(mask == MaskMax - 1)
return 1;
if(dp[mask] != -1) return dp[mask];
int i = 0;
while(mask & (1<<i)) i++;
int x = i/3 , y = i%3;
int ans = 0;
for(int j = 0 ; j<4 ; j++)
{
if(x+ dx[j] < 3 && x + dx[j] >=0 && y+dy[j]< 3 && y+dy[j] >=0 )
{
int pos = (x+dx[j])*3 + (y+dy[j]);
if(!(mask & (1<<pos)))
{
ans+=onefloar(mask | (1<<i) | (1<<pos));
ans%=mod;
}
}
}
return dp[mask] = ans;
}
int ans[maxi][MaskMax];
void solve()
{
memset(dp , -1 ,sizeof dp);
ans[0][0] = 1;
for(int a = 1 ; a<=maxi ; a++)
{
for(int i = 0 ; i<MaskMax ; i++)
for(int j = 0 ; j<MaskMax ; j++)
{
if(i&j || (a%2&&j==0) ) continue;
ans[a][j]+=(ans[a-1][i] * onefloar(i|j));
ans[a][j]%=mod;
}
}
}
int main() {
int t,n;
cin>>t;
solve();
while(t--)
{
scanf("%d", &n);
printf("%d\n" , ans[n][0]);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IG1heGkgPSA1MDAwOwpjb25zdCBpbnQgTWFza01heCA9IDE8PDk7CmludCBkcFtNYXNrTWF4XTsKaW50IGR4W10gPSB7MSAsIC0xICwgMCAsIDB9OwppbnQgZHlbXSA9IHswICwgMCAsIDEgLCAtMX07CmludCBtb2QgPSAxMDAwNzsKaW50IG9uZWZsb2FyKGludCBtYXNrKQp7CiAgICBpZihtYXNrID09IE1hc2tNYXggLSAxKQogICAgICAgIHJldHVybiAxOwogICAgaWYoZHBbbWFza10gIT0gLTEpIHJldHVybiBkcFttYXNrXTsKICAgIGludCBpID0gMDsKICAgIHdoaWxlKG1hc2sgJiAoMTw8aSkpIGkrKzsKICAgIGludCAgeCA9IGkvMyAsIHkgPSBpJTM7CiAgICBpbnQgYW5zID0gMDsKICAgIGZvcihpbnQgaiA9IDAgOyBqPDQgOyBqKyspCiAgICB7CiAgICAgIGlmKHgrIGR4W2pdIDwgMyAmJiB4ICsgZHhbal0gPj0wICYmIHkrZHlbal08IDMgJiYgeStkeVtqXSA+PTAgKQogICAgICB7CiAgICAgICAgICBpbnQgcG9zID0gKHgrZHhbal0pKjMgKyAoeStkeVtqXSk7CiAgICAgICAgICBpZighKG1hc2sgJiAoMTw8cG9zKSkpCiAgICAgICAgICB7CiAgICAgICAgICAgICBhbnMrPW9uZWZsb2FyKG1hc2sgfCAoMTw8aSkgfCAoMTw8cG9zKSk7CiAgICAgICAgICAgICBhbnMlPW1vZDsKICAgICAgICAgIH0KICAgICAgfQogICAgfQogICAgcmV0dXJuIGRwW21hc2tdID0gYW5zOwp9CmludCBhbnNbbWF4aV1bTWFza01heF07CnZvaWQgc29sdmUoKQp7CiAgICBtZW1zZXQoZHAgLCAtMSAsc2l6ZW9mIGRwKTsKICAgIGFuc1swXVswXSA9IDE7CiAgICBmb3IoaW50IGEgPSAxIDsgYTw9bWF4aSA7IGErKykKICAgIHsKICAgICAgICBmb3IoaW50IGkgPSAwIDsgaTxNYXNrTWF4IDsgaSsrKQogICAgICAgIGZvcihpbnQgaiA9IDAgOyBqPE1hc2tNYXggOyBqKyspCiAgICB7CiAgICAgICAgaWYoaSZqIHx8IChhJTImJmo9PTApICkgY29udGludWU7CiAgICAgICAgYW5zW2FdW2pdKz0oYW5zW2EtMV1baV0gKiBvbmVmbG9hcihpfGopKTsKICAgICAgICBhbnNbYV1bal0lPW1vZDsKICAgIH0KICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBpbnQgdCxuOwogICAgY2luPj50OwogICAgc29sdmUoKTsKICAgIHdoaWxlKHQtLSkKICAgIHsKICAgICAgc2NhbmYoIiVkIiwgJm4pOwogICAgICBwcmludGYoIiVkXG4iICwgYW5zW25dWzBdKTsKICAgIH0KCXJldHVybiAwOwp9Cg==