def t(m): l=[-1,0,0,0,1] for i in range(5,m+1): l+=[sum(l[-4:])%17] return l q=int(input()) n=[int(input()) for i in'.'*q] l=t(max(n)) for i in n: print(l[i])