import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Tetranacci solver = new Tetranacci(); solver.solve(1, in, out); out.close(); } static class Tetranacci { public void solve(int testNumber, Scanner in, PrintWriter out) { int q = in.nextInt(); int[] t = new int[1000005]; t[1] = 0; t[2] = 0; t[3] = 0; t[4] = 1; for (int i = 5; i <= 1000000; i++) { t[i] = (t[i - 1] + t[i - 2] + t[i - 3] + t[i - 4]) % 17; } for (int i = 0; i < q; i++) { out.println(t[in.nextInt()]); } } } }