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