#include <iostream> 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 x){ return (x % 4 == 0&& x % 100 != 0) || (x % 400 == 0); } int main(){ int n; cin >> n; while(n --){ int y,m,d,x,newd,flag; cin >> y >> m >> d >> x; x = x + d; d = 0; while(x >= daytab[isLeapYear(y)][m]){ x = x - daytab[isLeapYear(y)][m]; if(m == 12){ y ++; m = 1; }else{ m ++; } } d = d + x; if(d == 0){ m --; d = daytab[isLeapYear(y)][m]; } printf("%04d-%02d-%02d\n",y,m,d); } return 0; }