#include <iostream>
using namespace std;
int months[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}};
int isRun(int year){
    if(year%400==0 || (year%4==0 && year%100!=0)) return 1;
    else return 0;
}
int main(){
    int m,year,month,day;
    cin>>m;
    while(m--){
        cin>>year>>month>>day;
        if(day+1<=months[isRun(year)][month]) printf("%04d-%02d-%02d\n",year,month,day+1);
        else if(month!=12) printf("%04d-%02d-01\n",year,month+1);
        else printf("%04d-01-01\n",year+1);
    }
    return 0;
}