#include <bits/stdc++.h> using namespace std; const int months[]={ 0,31,28,31,30,31,30,31,31,30,31,30,31 }; int is_leap(int year){ if((year%4==0 && year%100!=0) || year%400 == 0){ return 1; } return 0; } int get_days(int year, int month){ int res = months[month]; if (month == 2){ res += is_leap(year); } return res; } int main(){ int t; cin >> t; while (t --){ int year, month, day, a; cin >> year >> month >> day >> a; a = a + day; while (a > get_days(year, month)){ a = a - get_days(year, month); month = (month + 1); if (month == 13){ month = 1; year ++; } } printf("%04d-%02d-%02d\n", year, month, a); } return 0; }