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