#include<stdio.h>

int main (void){

  int n,i;
  int year,month,day;
  int countd;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&year,&month,&day);
    countd = 0;
    
    if(999-year == 0){
      countd += 0;
    }else if(999-year !=0){
             if((999-year)%3 == 1){
	       countd += 590*((999-year)/3)+200;
	     }else if((999-year)%3 == 2){
	       countd += 590*((999-year)/3)+395;
	     }else if((999-year)%3 == 0){
	       countd += 590*((999-year)/3);
	     }
    }
    
    if(year%3 != 0){
      if((10-month)%2 == 1){
	countd += 39*((10-month)/2)+20;
      }else if((10-month)%2 == 0){
	countd += 39*((10-month)/2);
      }
      
      if(month%2 == 1){
	countd += 20-day;
      }else if(month%2 == 0){
	countd += 20-day;
      }
    }else{
      countd += 20*(10-month);
    
      countd += 21-day;
    }

printf("%d\n",countd);
  }
  return 0;
}
      