#include <iostream>
using namespace std;

#define isLeapYear(x) ((x%4==0 && x%100!=0)||(x%400 == 0))

int leap_months[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int avg_months[] = { 31,29,31,30,31,30,31,31,30,31,30,31 };

void addOneDay(int year,int month,int day)
{
    int next = day+1;
    int *months= isLeapYear(year)?leap_months:avg_months;
    if (next > months[month-1]) {
        printf("%d-%02d-%02d\n",year,month+1,1);
    }
    else{
        printf("%d-%02d-%02d\n",year,month,day+1);
    }
}

int main()
{
    int m,year,month,day;
    while (cin >> m) {
        for (int i = 0; i < m; ++i) {
            cin >> year >> month >> day;
            addOneDay(year,month,day);
        }
    }
    return 0;
}