using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var Q = int.Parse(ReadLine()); var n = new int[Q]; for (int i = 0; i < Q; i++) { n[i] = int.Parse(ReadLine()); } var T = new int[1000000]; T[3] = 1; for (int j = 4; j < T.Length; j++) { T[j] = (T[j - 1] + T[j - 2] + T[j - 3] + T[j - 4]) % 17; } for (int i = 0; i < Q; i++) { WriteLine(T[n[i] - 1]); } } }