from calendar import weekday, day_name
month, date, year = map(int, input().split())
print(day_name[weekday(year, month, date)].upper())
from datetime import datetime
def time_delta(t1, t2):
time_format = '%a %d %b %Y %H:%M:%S %z'
time1 = datetime.strptime(t1, time_format)
time2 = datetime.strptime(t2, time_format)
print(int((abs(time1 - time2)).total_seconds()))
if __name__ == '__main__':
for _ in range(int(input())):
time_delta(input(), input())