from collections import defaultdict Q = int(input()) N = 10 ** 5 T = [0] * (N + 1) T[4] = 1 dic = defaultdict(int) tmp = sum(T[1:5]) for i in range(5, N + 1): T[i] = tmp if tuple(T[i - 4:i]) not in dic: dic[tuple(T[i - 4:i])] = i else: start = dic[tuple(T[i - 4:i])] seq = i - start break tmp += T[i] - T[i - 4] tmp %= 17 for _ in range(Q): n = int(input()) if n <= start: print(T[n]) else: print(T[start + (n - start) % seq])