#include <stdbool.h>
#include <stdio.h>
bool learyear(year)
{
    return (year%4==0 && year%100!=0||year%400==0);
}
int main() {
   int m=0;
   scanf("%d",&m);
   int Days[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},
            {0,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
   while(m--)
   {
        int year,month,day,days;
        scanf("%d %d %d %d",&year,&month,&day,&days);
        int sum = day + days;
        while(sum>Days[learyear(year)][month])
        {
            sum-=Days[learyear(year)][month];
            ++month;
            if(month==13)
            {
                ++year;
                month=1;
            }
        } 
        day=sum;
        if(month<10)
        {
            if(day<10)
            {
                printf("%d-0%d-0%d\n",year,month,day);
            }
            else {
                printf("%d-0%d-%d\n",year,month,day);
            }
        }
        else
        {
            if(day<10)
            {
                printf("%d-%d-0%d\n",year,month,day);
            }
            else {
              printf("%d-%d-%d\n",year,month,day);
            }
        }
   }
  
    return 0;
}