while True:
try:
year,moon,day = map(int,input().split())
a = [31,28,31,30,31,30,31,31,30,31,30,31] #所有月份对应的天数 (平年)
b = [31,29,31,30,31,30,31,31,30,31,30,31] #所有月份对应的天数 (闰年)
if(year % 4 == 0) & (year % 100 != 0) | (year % 400 == 0): #判断是否闰年
date = 0
for i in range(moon - 1):
date += b[i]
date += day
print(date)
else:
date = 0
for i in range(moon - 1):
date += a[i]
date += day
print(date)
except:
break