#include <iostream>
using namespace std;
bool IsLeap(int year){
    if (year%4==0||(year%4==0&&year%100!=0))
        return true;

return false;
}
int main()

{   int A[]={31,28,31,30,31,30,31,31,30,31,30,31};
    int year,month,day,sum,addNumber;
    int times=0;
        scanf("%d",×);
   while(times>0){
       scanf("%d %d %d %d",&year,&month,&day,&addNumber);
        int seq=0;
    if(IsLeap(year)){
        A[1]=29;
    }else{
        A[1]=28;
    }
    while(month>1){
           seq+=A[month-2];
        month--;
    }
      sum=seq+day;


      sum+=addNumber;//µÚsumÌì
    month=1;
    while(A[month-1]<sum){
    sum-=A[month-1];
    if(month+1>12) {
            year++;
    month=(month+1)%12;

    if(IsLeap(year)){//年份变了,重新判断是否为闰年
        A[1]=29;
    }else{
        A[1]=28;
    }


    }else{
        month++;
    }

   }
   printf("%4d-%02d-%02d\n",year,month,sum);
    times--;
}
}