#include <stdio.h>
int main(){
  int n,year,month,day,sum,i,j,k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    sum=0;
    scanf("%d%d%d",&year,&month,&day);
    for(j=1;j<=year;j++){
      if(j!=year){
	if(j%3==0)sum+=200;
	else sum+=195;
      }
      else if(j=year){
	if(j%3!=0){
	  for(k=1;k<=month;k++){
	    if(k!=month){
	      if(k%2==0)sum+=19;
	      else sum+=20;
	    }
	    else if(k==month){
	      sum+=day;
	    }
	  }
	}
	else {
	  sum+=20*(month-1);
	  sum+=day;
	}
      }
    }
	
    
    printf("%d\n",196471-sum);
  }

  return 0;
}    