#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int m;
	cin>>m;
	int year,mon,day;
	int mday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

	while(m--)
	{
		scanf("%d%d%d",&year,&mon,&day);
		if(year%400==0||year%4==0&&year%100!=0){
			mday[2]=29;
		}	
		else
		{
			mday[2]=28;
		}
		day++;
		if(day>mday[mon])
		{
			day=1;
			mon++; 
				if(mon>12){
					day=1;
					mon=1;
					year++;
				}
				
		}
		printf("%04d-%02d-%02d\n",year,mon,day);
	}
	
	
	
	
	
	
	
}

nextday思路