#include<bits/stdc++.h>
using namespace std;
int A[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int n;
int y,m,d;
cin>>n;
while(n--){
cin>>y>>m>>d;
d++;
if(d>A[m]){
d=1;
m++;
if(m>12){
m=1;
y++;
}
}
cout<<y<<"-"<<setw(2)<<setfill('0')<<m<<"-"<<setw(2)<<setfill('0')<<d<<endl;
}
return 0;
}