#include<iostream>
#include<cstdio>
using namespace std;
int DayTab[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}
};
bool IsLeapYear(int year) {
return (year % 4 == 0 && year % 10 != 0) || (year % 400 == 0);
}
int YearTab[2] = { 365,366 };
int main() {
int year, month, day, number;
int m, num;
scanf("%d\n", &m);
while (m--) {
scanf("%d%d%d%d\n", &year, &month, &day, &number);
num = 0;
for (int i = 0; i < month; ++i) {
num += DayTab[IsLeapYear(year)][i];
}
num += day;
number += num;
while (number > YearTab[IsLeapYear(year)]) {
number -= YearTab[IsLeapYear(year)];
++year;
}
month = 0;
while (number > DayTab[IsLeapYear(year)][month]) {
number -= DayTab[IsLeapYear(year)][month];
++month;
}
day = number;
cout << year << "-";
if (month < 10) {
cout << 0 << month << "-";
}
else {
cout << month << "-";
}
if (number < 10) {
cout << 0 << day << endl;
}
else {
cout << day << endl;
}
}
return 0;
}
#include<cstdio>
using namespace std;
int DayTab[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}
};
bool IsLeapYear(int year) {
return (year % 4 == 0 && year % 10 != 0) || (year % 400 == 0);
}
int YearTab[2] = { 365,366 };
int main() {
int year, month, day, number;
int m, num;
scanf("%d\n", &m);
while (m--) {
scanf("%d%d%d%d\n", &year, &month, &day, &number);
num = 0;
for (int i = 0; i < month; ++i) {
num += DayTab[IsLeapYear(year)][i];
}
num += day;
number += num;
while (number > YearTab[IsLeapYear(year)]) {
number -= YearTab[IsLeapYear(year)];
++year;
}
month = 0;
while (number > DayTab[IsLeapYear(year)][month]) {
number -= DayTab[IsLeapYear(year)][month];
++month;
}
day = number;
cout << year << "-";
if (month < 10) {
cout << 0 << month << "-";
}
else {
cout << month << "-";
}
if (number < 10) {
cout << 0 << day << endl;
}
else {
cout << day << endl;
}
}
return 0;
}