#include <iostream>
using namespace std;
int GetMonthDay(int year, int month)
{
	int array[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	if (month == 2 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0))
	{
		return array[month] + 1;
	}
	return array[month];
}
int main() {
    int a;
    int year,month,day,_day;
    cin>>a;
    while(a--)
    {
        cin>>year>>month>>day>>_day;
        day+= _day;
        while(day>GetMonthDay(year, month))
        {
            day-=GetMonthDay(year,month);
            month++;
            if(month==13)
            {
                year++;
                month = 1;
            }
        }

        printf("%04d-%02d-%02d\n", year, month, day);
    }  
}
// 64 位输出请用 printf("%lld")