using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var Q = int.Parse(ReadLine()); var T = new int[4912]; T[3] = 1; for (int j = 4; j < 4912; 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[(int.Parse(ReadLine()) - 1) % 4912]); } }