//土尔逊Torson 编写于2023/3/31
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

using namespace std;

struct date {
	int year;
	int mon;
	int day;
};

int main()
{
	int mday[13] = { -1,31,28,31,30,31,30,31,31,30,31,30,31 };
	int num;
	struct date * dt;
	scanf("%d", &num);

	dt = (struct date *)malloc(num*sizeof(struct date));

	for (int i = 0; i < num; ++i) {
		scanf("%d %d %d", &dt[i].year, &dt[i].mon, &dt[i].day);
	}

	for (int i = 0; i < num; ++i) {
		++dt[i].day;
		if (dt[i].day > mday[dt[i].mon]) {
			dt[i].day = 1;
			++dt[i].mon;
			if (dt[i].mon > 12) {
				dt[i].mon = 1;
				++dt[i].year;
			}
		}
		printf("%04d-%02d-%02d\n", dt[i].year, dt[i].mon, dt[i].day);
	}
	//system("pause");
	return EXIT_SUCCESS;
}