class Date{
public:
bool isleapyear(int year){
return year%4==0&&year%100!=0||year%400==0;
}
int getmonthday(int year,int month){
static int monthday[]={31,28,31,30,31,30,31,31,30,31,30,31};
return monthday[month-1]+(month==2&& isleapyear(year)?1:0);
}
Date()
{
int extday;
scanf("%d%d%d%d",&_year,&_month,&_day,&extday);
_day+=extday;
while(_day>getmonthday(_year, _month)){
_day-=getmonthday(_year, _month++);
if(_month==13){
_year++;
_month=1;
}
}
}
void display(){
printf("%04d-%02d-%02d\n",_year,_month,_day);
}
private:
int _year;
int _month;
int _day;
};
int main(){
int n;
scanf("%d",&n);
Date data [n];
for(int i=0;i<n;i++){
data[i].display();
}
return 0;
}