#include <bits/stdc++.h>
using namespace std;

int a1[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int a2[] = {0,31,29,31,30,31,30,31,31,30,31,30,31};

bool isrun(int y){
	if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
		return true;
	else
		return false;
} 

int main(){
	int cnt,y,m,d;
	cin>>cnt;
	while(cnt--){
		cin>>y>>m>>d;
		if(isrun(y)){
			d++;
			if(d > a2[m]){
				d -= a2[m];
				m++;
			}
				
		}else{
			d++;
			if(d > a1[m]){
				d -= a1[m];
				m++;
			}
				
		}
		printf("%d-%02d-%02d\n",y,m,d);
	}
}