#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int m = 1000000, k = 90000, j = 0;
    vector<int> p(m);
    p[3] = 1;
    for (int i = 4; i < m; i++) {
        p[i] = (p[i - 1] + p[i - 2] + p[i - 3] + p[i - 4]) % 17;
        if (i > k && p[i] == p[k] && p[i - 1] == p[k - 1] && p[i - 2] == p[k - 2] && p[i - 3] == p[k - 3]) {
            j = i - k;
            break;
        }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int64_t n;
        cin >> n;
        n--;

        if (n > k) {
            n = (n - k) % j + k;
        }
        cout << p[n] << '\n';
    }

    return 0;
}