//直接按月继续累计即可
#include <iostream>
using namespace std;int main() {
int year,month,day,run;
int m,number;
cin>>m;
int yy[2][12]={
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}
};
while(m!=0){
cin>>year>>month>>day>>number;
if((year%4==0&&year%100!=0)||(year%400==0))run=1;
else run=0;
number+=day;
while(number>yy[run][month-1]){
number-=yy[run][month-1];
month++;
if(month>12){ //超过一年,重新判断闰年
year++;
if((year%4==0&&year%100!=0)||(year%400==0))run=1;
else run=0;
month=month-12;
}
}
printf("%04d-%02d-%02d\n",year,month,number);
m--;
}
}