#include <bits/stdc++.h> using namespace std; int a1[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; bool isrun(int y){ if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) return true; else return false; } int main(){ int cnt,y,m,d,k,sum; cin>>cnt; while(cnt--){ cin>>y>>m>>d>>k; sum = d + k; for(; (sum > a1[m] && m <= 12) || m == 2; m++){ if(isrun(y) && m == 2) sum -= 29; else sum -= a1[m]; } if(m > 12){ y++; for(m = 1; (sum > a1[m] && m <= 12) || m == 2; m++){ if(isrun(y) && m == 2) sum -= 29; else sum -= a1[m]; } } printf("%d-%02d-%02d\n",y,m,sum); } }