#include<iostream>
using namespace std;

void nextDay(int &year,int &month,int &day){
	int dayOfMonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	int isLeap;
	isLeap=(year%400==0 || (year%4==0 && year%100!=0));
	if(isLeap==1)	dayOfMonth[2]=29;	
	else	dayOfMonth[2]=28;
	day++;
	if(day>dayOfMonth[month]){
		day=1;
		month++;
	}
	if(month>12){
		month=1;
		year++;
	}
	printf("%d-%02d-%02d\n",year,month,day);
	//cout<<year<<"-"<<month<<"-"<<day<<endl;
}

struct Day{
	int y;
	int m;
	int d;
}day1[100];

int main(){
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>day1[i].y>>day1[i].m>>day1[i].d;
		nextDay(day1[i].y,day1[i].m,day1[i].d);
	}
	return 0;
}