#include<stdio.h> 
 int n,y,m,d,i,total;
 void year(void){
   if(y%3==0){
      total+=(999-y)/3*590;
   }else if(y%3==1){
      total+=(998-y)/3*590+200;
   }else {
     total+=(997-y)/3*590+395;
   }
}
void month(void){
   if(y%3!=0){
    if(m%2==0){
     total+=(10-m)/2*39;
    }else{
     total+=(9-m)/2*39+19;
    }
   }else{
     total+=(10-m)*20;
   }
}
void day(void){
  if(y%3!=0){
    if(m%2==0){
       total+=20-d;
      }else{
          total+=21-d;
     }
   }else{
       total+=21-d;
   }
}
int main(void){

  scanf("%d",&n);
    for(i=0;i<n;i++){
         total=0;
         scanf("%d %d %d",&y,&m,&d);
         year();
         month(); 
         day();
         printf("%d\n",total);
     }
   return 0;
}

    