#include <stdio.h>
int main()
{
int n,y,m,d,i;
scanf("%d",&n);
for (i=1; i<=n; i++)
{
while(scanf("%d-%d-%d",&y,&m,&d)!=EOF)
{
if((y%400==0)||((y%100!=0)&&(y%4==0)))
{
switch(m)
{
case 01 : if(d<=31&&d>0) printf("%d\n",d); else printf("error date!\n");break;
case 02 : if(d<=29&&d>0) printf("%d\n",d+31); else printf("error date!\n");break;
case 03 : if(d<=31&&d>0) printf("%d\n",d+60); else printf("error date!\n");break;
case 04 : if(d<=30&&d>0) printf("%d\n",d+91); else printf("error date!\n");break;
case 05 : if(d<=31&&d>0) printf("%d\n",d+121); else printf("error date!\n");break;
case 06 : if(d<=30&&d>0) printf("%d\n",d+152); else printf("error date!\n");break;
case 07 : if(d<=31&&d>0) printf("%d\n",d+182); else printf("error date!\n");break;
case 08 : if(d<=31&&d>0) printf("%d\n",d+213); else printf("error date!\n");break;
case 09 : if(d<=30&&d>0) printf("%d\n",d+244); else printf("error date!\n");break;
case 10 : if(d<=31&&d>0) printf("%d\n",d+274); else printf("error date!\n");break;
case 11 : if(d<=30&&d>0) printf("%d\n",d+305); else printf("error date!\n");break;
case 12 : if(d<=31&&d>0) printf("%d\n",d+335); else printf("error date!\n");break;
default : printf("error date!\n");
}
}
else
{
switch(m)
{
case 01 : if(d<=31&&d>0) printf("%d\n",d); else printf("error date!\n");break;
case 02 : if(d<=28&&d>0) printf("%d\n",d+31); else printf("error date!\n");break;
case 03 : if(d<=31&&d>0) printf("%d\n",d+59); else printf("error date!\n");break;
case 04 : if(d<=30&&d>0) printf("%d\n",d+90); else printf("error date!\n");break;
case 05 : if(d<=31&&d>0) printf("%d\n",d+120); else printf("error date!\n");break;
case 06 : if(d<=30&&d>0) printf("%d\n",d+151); else printf("error date!\n");break;
case 07 : if(d<=31&&d>0) printf("%d\n",d+181); else printf("error date!\n");break;
case 08 : if(d<=31&&d>0) printf("%d\n",d+212); else printf("error date!\n");break;
case 09 : if(d<=30&&d>0) printf("%d\n",d+243); else printf("error date!\n");break;
case 10 : if(d<=31&&d>0) printf("%d\n",d+273); else printf("error date!\n");break;
case 11 : if(d<=30&&d>0) printf("%d\n",d+304); else printf("error date!\n");break;
case 12 : if(d<=31&&d>0) printf("%d\n",d+334); else printf("error date!\n");break;
default : printf("error date!");
}
}
}
}
}
int main()
{
int n,y,m,d,i;
scanf("%d",&n);
for (i=1; i<=n; i++)
{
while(scanf("%d-%d-%d",&y,&m,&d)!=EOF)
{
if((y%400==0)||((y%100!=0)&&(y%4==0)))
{
switch(m)
{
case 01 : if(d<=31&&d>0) printf("%d\n",d); else printf("error date!\n");break;
case 02 : if(d<=29&&d>0) printf("%d\n",d+31); else printf("error date!\n");break;
case 03 : if(d<=31&&d>0) printf("%d\n",d+60); else printf("error date!\n");break;
case 04 : if(d<=30&&d>0) printf("%d\n",d+91); else printf("error date!\n");break;
case 05 : if(d<=31&&d>0) printf("%d\n",d+121); else printf("error date!\n");break;
case 06 : if(d<=30&&d>0) printf("%d\n",d+152); else printf("error date!\n");break;
case 07 : if(d<=31&&d>0) printf("%d\n",d+182); else printf("error date!\n");break;
case 08 : if(d<=31&&d>0) printf("%d\n",d+213); else printf("error date!\n");break;
case 09 : if(d<=30&&d>0) printf("%d\n",d+244); else printf("error date!\n");break;
case 10 : if(d<=31&&d>0) printf("%d\n",d+274); else printf("error date!\n");break;
case 11 : if(d<=30&&d>0) printf("%d\n",d+305); else printf("error date!\n");break;
case 12 : if(d<=31&&d>0) printf("%d\n",d+335); else printf("error date!\n");break;
default : printf("error date!\n");
}
}
else
{
switch(m)
{
case 01 : if(d<=31&&d>0) printf("%d\n",d); else printf("error date!\n");break;
case 02 : if(d<=28&&d>0) printf("%d\n",d+31); else printf("error date!\n");break;
case 03 : if(d<=31&&d>0) printf("%d\n",d+59); else printf("error date!\n");break;
case 04 : if(d<=30&&d>0) printf("%d\n",d+90); else printf("error date!\n");break;
case 05 : if(d<=31&&d>0) printf("%d\n",d+120); else printf("error date!\n");break;
case 06 : if(d<=30&&d>0) printf("%d\n",d+151); else printf("error date!\n");break;
case 07 : if(d<=31&&d>0) printf("%d\n",d+181); else printf("error date!\n");break;
case 08 : if(d<=31&&d>0) printf("%d\n",d+212); else printf("error date!\n");break;
case 09 : if(d<=30&&d>0) printf("%d\n",d+243); else printf("error date!\n");break;
case 10 : if(d<=31&&d>0) printf("%d\n",d+273); else printf("error date!\n");break;
case 11 : if(d<=30&&d>0) printf("%d\n",d+304); else printf("error date!\n");break;
case 12 : if(d<=31&&d>0) printf("%d\n",d+334); else printf("error date!\n");break;
default : printf("error date!");
}
}
}
}
}