#yuki657 def tet(x): t=[0,0,0,1] for i in xrange(5,x+1): t+=[((t[-1]+t[-2]+t[-3]+t[-4])%17)] return t q=int(raw_input()) for i in xrange(q): n=int(raw_input()) print tet(n)[-1]