#!/usr/bin/python
# -*- coding: UTF-8 -*-
import datetime
a=int(input())
for i in range(a):
date1=input()
c=datetime.date(date1,5,1).weekday()
if c==0: x=9
if c==1: x=6
if c==2: x=5
if c==3: x=5
if c==4: x=5
if c==5: x=5
if c==6: x=6
print x