#include <stdio.h>
int table[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
int main() {
    int count;
    int year, month, day;
    scanf("%d", &count);
    while (count--) {
        scanf("%d %d %d", &year, &month, &day);
        day += 1;
        if (day > table[0][month]) {
            month += 1;
            day = 1;
        }
        if (month > 12) {
            year += 1;
            month = 1;
            day = 1;
        }
        printf("%04d-%02d-%02d\n", year, month, day);
    }
    return 0;
}