#include <cstdio>
#include <iostream>
#include <iomanip>
using namespace std;
int isPyear(int y){
    return (y%4==0 && y%100!=0)||(y%400==0);
}
int laterday(int* mt){
    int year=*mt;
    int month=*(mt+1);
    int day=*(mt+2);
    int a,b,c;
    int daysEach[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}};
    if(day==31 && month==12) {
        *mt=year+1;
        *(mt+1)=1;
        *(mt+2)=1;
    }
    else if(day+1>daysEach[isPyear(year)][month]) {
        *(mt+1)=month+1;
        *(mt+2)=1;
    }
    else *(mt+2)=day+1;
    return 1;
}

int main() {
int m;
cin>>m;
int mt[m][3];
for(int i=0;i<m;i++){
    for(int j=0;j<3;j++)
    cin>>mt[i][j];
}
for(int i=0;i<m;i++){
    laterday(&mt[i][0]);
}
int f=1;
for(int i=0;i<m;i++){
    f=1;
    for(int j=0;j<3;j++){
        if(f==0) printf("-%02d",mt[i][j]);
        else {
            cout<<mt[i][j];
            f=0;}
    }
    cout<<endl;
}
}
// 64 位输出请用 printf("%lld")