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