from datetime import datetime, timedelta,date m = int(input()) while True: try: if m == 0: break m -= 1 y, m, d, ds = list(map(int, input().split())) dt = datetime(y, m, d) now = dt + timedelta(days=ds) print(now.strftime('%Y-%m-%d')) except: break
a=int(input()) ls=[[" "]*4 for i in range(a)] for i in range(a): b=input().split() b=[int(x) for x in b] ls[i][0]=b[0] ls[i][1]=b[1] ls[i][2]=b[2] ls[i][3]=b[3] for i in range(a): a1=0 a2=0 lst=[31,28,31,30,31,30,31,31,30,31,30,31] if ls[i][0]%4==0 and ls[i][0]%400!=0: lst[1]=29 elif ls[i][0]%400==0: lst[1]=29 for j in range(ls[i][1]-1): a1+=lst[j] a1+=ls[i][2] a1+=ls[i][3] op1=1 j=0 while True: if a1<=lst[j]: break else: op1+=1 a1-=lst[j] if op1>12: op1=1 ls[i][0]+=1 j=0 else: j+=1 if ls[i][0]%4==0 and ls[i][0]%400!=0: lst[1]=29 elif ls[i][0]%400==0: lst[1]=29 else: lst[1]=28 ls[i][1]=op1 ls[i][2]=a1 for i in range(a): print("{}-{:02d}-{:02d}".format(ls[i][0],ls[i][1],ls[i][2]))