import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int[][] A = [[1,1,1,1], [1,0,0,0], [0,1,0,0], [0,0,1,0]]; int q; scan(q); while (q--) { long n; scan(n); n--; auto res = mul(powMat(A, n), [[1],[0],[0],[0]]); writeln(res[3][0]); } } int[][] powMat(int[][] A, long x) { if (x > 0) { auto res = square(powMat(A, x>>1)); if (x & 1) { res = mul(res, A); } return res; } else { auto res = new int[][](A.length, A.length); foreach (i ; 0 .. A.length) res[i][i] = 1; return res; } } int[][] square(int[][] A) { assert(A[0].length == A.length); auto B = new int[][](A.length, A.length); foreach (i ; 0 .. A.length) { foreach (j ; 0 .. A.length) { foreach (k ; 0 .. A.length) { B[i][j] += A[i][k] * A[k][j]; B[i][j] %= 17; } } } return B; } auto mul(int[][] A, int[][] B) { assert(A[0].length == B.length); auto N = A.length; auto M = B[0].length; auto C = new int[][](N, M); foreach (i ; 0 .. N) { foreach (j ; 0 .. M) { foreach (k ; 0 .. A[i].length) { C[i][j] += A[i][k] * B[k][j]; C[i][j] %= 17; } } } return C; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }