#include <bits/stdc++.h>

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)
const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };
#define MAX_N (int)2e5+20
typedef long long ll;
using namespace std;

int q;
int main(){
    int t[1000001];
    t[0] = 0;
    t[1] = 0;
    t[2] = 0;
    t[3] = 1;
    rep(i,4,1000001){
        t[i] = (t[i-1]+t[i-2]+t[i-3]+t[i-4])%17;
    }
    scanf("%d",&q);
    rep(i,0,q){
        int n;
        cin >> n;
        printf("%d\n",t[n-1]);        
    }
}