weekday=["Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday"]
m_day=[0,31,28,31,30,31,30,31,31,30,31,30,31]

n=int(input())
for i in range(n):
    year,month,day=map(int,input().split())
    days=0
    if  (year%400==0 or (year%4==0 and year%100!=0 )):   #如果闰年2月为29天
        m_day[2]=29
    if month<1 or month>12 or day <1 :
        print("Illegal")
    elif day>m_day[month]:
        print("Illegal")    
    else:
        if year<2020:
            for i in range(year,2020):  #计算整年的天数
                if (i%400==0 or (i%4==0 and i%100!=0 )):
                    days-=366
                else:
                    days-=365
        for  k  in range(1,month):  #计算月份的天数
            days+=m_day[k]
        days+=day
       
        #以下还是有问题的地方
        days-=323   #2020年11月18日当年的天数
        w=(days)%7    #与2020年11-18 相差的天数
        print(days,weekday[(w+3)%7])