#include <iostream> using namespace std; int p[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int Run(int k) { if((k%400==0)||((k%4==0)&&(k%100!=0)))return 1; else return 0; } int main() { int y,m,d; int n;cin>>n; while (cin >> y >> m >>d) { if(Run(y)==1)p[2]=29; else p[2]=28; if(d==p[m]){ d=1; m++; } else d++; if(m>12) { y++; m=1; } printf("%04d-%02d-%02d\n",y,m,d);//ymd不用取地址 } }