#include<bits/stdc++.h> using namespace std; bool leap_judge(int a) { return (((a%4==0)&&(a%100!=0))||a%400==0); } int main() { int m1[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int m2[12]={31,29,31,30,31,30,31,31,30,31,30,31}; vector<int> r;//存储结果 int n; int a,b,c,d; int leave;//这一年还留下多少天 scanf("%d\n",&n); for(int i=0;i<n;i++) { scanf("%d %d %d %d",&a,&b,&c,&d); while(d!=0) { //闰年 if(leap_judge(a)) { leave=0; for(int j=b;j<12;j++) { leave=leave+m2[j]; } leave=leave+m2[b-1]-c;//算出还有这一年中还有多少天 //printf("%d",leave); if(d>leave) { d=d-leave; a=a+1; b=1; c=0; } else { while(true) { if(d>(m2[b-1]-c)) { d=d-m2[b-1]+c; b=b+1; c=0; } else { r.push_back(a); r.push_back(b); r.push_back(d); d=0; break; } } } }//下面是平年 else { leave=0; for(int j=b;j<12;j++) { leave=leave+m1[j]; } leave=leave+m1[b-1]-c;//算出还有这一年中还有多少天 if(d>leave) { d=d-leave; a=a+1; b=1; c=0; } else { while(true) { if(d>(m1[b-1]-c)) { d=d-m1[b-1]+c; b=b+1; c=0; } else { r.push_back(a); r.push_back(b); r.push_back(d); d=0; break; } } } } } } //输出部分 for(int i=0;i<r.size()/3;i++) { printf("%04d-%02d-%02d\n",r[3*i],r[3*i+1],r[3*i+2]); } }