l=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73]
t=int(raw_input())
def chk(z):
	s=0
	for i in z:
		s+=int(i)
	return(s);
while(t):
	z=list(raw_input())
	s=chk(z)
	if(s in l):
		print "YES"
	else:
		print "NO"
	t-=1