#include<iostream>
#include<stdio.h>
using namespace std;
//闰年
bool judge(int year){
if(year%100==0){
if(year%400==0) return true;
else return false;
}else{
if(year%4==0)return true;
else return false;
}
}
int main(){
int T;cin>>T;
int y,m,d;
int days[12]={0,31,59,90,120,151,181,212,243,273,304,334};
while(T--){
scanf("%d:%d:%d",&y,&m,&d);
if(judge(y)==true){
if(m>2){
cout<<days[m-1]+d+1<<endl;
}else{
cout<<days[m-1]+d<<endl;
}
}else{
cout<<days[m-1]+d<<endl;
}
}
return 0;
}
找众数