#include<iostream>
#include <string>
#include<map>
using namespace std;

int isLearYear(int year) {
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
        return 1;
    }
    return 0;
}

int main() {
    int n, y, m, d;
    cin >> n;
    map<int, int> maps = { {1, 31}, {2, 28}, {3, 31}, {4, 30}, {5, 31}, {6, 30}, {7, 31}, {8, 31}, {9, 30}, {10, 31}, {11, 30}, {12, 31} };
    for (int i = 0; i < n; i++) {
        cin >> y >> m >> d;
        //对天数加一
        d += 1;
        //对月份处理
        if (isLearYear(y) == 1 && m == 2) {
            if (d > (maps[m] + 1)) {//这里要注意二者操作的先后顺序,否则d会减错值
			    d -= (maps[m] + 1);
                m += 1;
            }
        } else {
            if (d > maps[m]) {//这里要注意二者操作的先后顺序,否则d会减错值
                d -= maps[m];
                m += 1;
            }
        }
        //对年份处理
        if (m > 12) {
            y += 1;
            m -= 12;
        }
        printf("%d-%02d-%02d\n", y, m, d);
    }

    return 0;
}
// 64 位输出请用 printf("%lld")