#include <iostream>
#include <cstdio>
using namespace std;
int is_run(int year)
{
if(year%100!=0&&year%4==0)
return 1;
if(year%400==0)
return 1;
else
return 0;
}
int main()
{
int k;
cin>>k;
while(k--)
{
int year,month,day;
int sum=0;
int data=0,data2=0;
scanf("%d-%d-%d",&year,&month,&day);
for(int i=year+1;i<=year+18;i++)
if(is_run(i))
data++;
if(month==2&&day==29)
{
if(is_run(year+18))
data2=0;
else
sum=-1;
}
if(month==1)
{
// cout<<"it is me1"<<endl;
if(is_run(year))
{
data2=1;
}
else
data2=0;
}
if(month==2&&day!=29)
{
// cout<<"it is me2"<<endl;
if(is_run(year))
{
data2=1;
}
else
data2=0;
}
int data3=0;
if(month==1)
{
if(is_run(year+18))
data3=-1;
}
if(month==2&&day!=29)
{
if(is_run(year+18))
data3=-1;
}
if(sum!=-1)
sum=18*365+data+data2+data3;
cout<<sum<<endl;
}
return 0;
}