import java.io.*; import java.util.*; public class Main_yukicoder658 { private static Scanner sc; private static Printer pr; private static void solve() { int q = sc.nextInt(); int[] aa = {0, 0, 0, 1}; int[][] xx = {{0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 1, 1, 1}}; long[] n = new long[q]; for (int i = 0; i < q; i++) { n[i] = sc.nextLong(); if (n[i] < 4) { pr.println(0); } else { int[] a = aa; int[][] x = xx; long loop = n[i] - 4; while (loop > 0) { if (loop % 2 == 1) { a = Matrix.mul(x, a); } x = Matrix.mul(x, x); loop /= 2; } pr.println(a[3]); } } } private static final int MOD = 17; private static class Matrix { static int[] mul(int[][] x, int[] a) { int n = a.length; int[] b = new int[n]; for (int i = 0; i < n; i++) { long tmp = 0; for (int j = 0; j < n; j++) { tmp += (long)x[i][j] * a[j]; tmp %= MOD; } b[i] = (int)tmp; } return b; } static int[][] mul(int[][] x, int[][] x2) { int n = x[0].length; int[][] b = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long tmp = 0; for (int k = 0; k < n; k++) { tmp += (long)x[i][k] * x2[k][j]; tmp %= MOD; } b[i][j] = (int)tmp; } } return b; } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }