import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== int[] ans = new int[1000010]; public void solve() { ans[3] = ans[4] = 1; for (int i = 5; i < 1000010; i++) { ans[i] = (ans[i-1] * 2 - ans[i-5]) % 17; // out.println("T[" + (i+1) + "] = " + ans[i] + " T[" + i // + "] = " + ans[(i-1)] + " * 2 - T[" + (i - 4) + "] = " + ans[i-5]); if(ans[i] < 0) { ans[i] += 17; // out.println(" --> T[" + (i+1) + "] = " + ans[i]); } } int Q = Integer.parseInt(sc.next()); int n; for (int i = 0; i < Q; i++) { n = Integer.parseInt(sc.next()); out.println(ans[n-1]); } } }