#include<stdio.h>
int month[][2]={
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31,
};
int isYeap(int y){
int ret=0;
if(y%4==0&&y%100!=0 || y%400==0) ret=1;
return ret;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
while(n--){
int y,m,d;
int sum=0;
scanf("%d:%d:%d",&y,&m,&d);
for(int i=1;i<m;i++){
sum+=month[i][isYeap(y)];
}
sum+=d;
printf("%d\n",sum);
}
}
return 0;
}
int month[][2]={
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31,
};
int isYeap(int y){
int ret=0;
if(y%4==0&&y%100!=0 || y%400==0) ret=1;
return ret;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
while(n--){
int y,m,d;
int sum=0;
scanf("%d:%d:%d",&y,&m,&d);
for(int i=1;i<m;i++){
sum+=month[i][isYeap(y)];
}
sum+=d;
printf("%d\n",sum);
}
}
return 0;
}