d = {0:6,1:9,2:6,3:5,4:5,5:5,6:5} for tcase in range(int(input())): year,t = int(input()),2 for i in range(1929,year+1): t += 366 if i%4==0 and i%100!=0 or i%400==0 else 365 print(d[t%7])