#include<stdio.h>
int main(){

  int n,i,j,y,m,d,count;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    count=0;
    scanf("%d%d%d",&y,&m,&d);
    for(j=0;j<999-y;j++){
      if(j%3==0){
	count+=200;
      }else{
	count+=195;
      }
    }
    for(j=0;j<10-m;j++){
      if(y%3==0){
	count+=20;
      }else{
	if(j%2==0){
	  count+=19;
	}else{
	  count+=20;
	}
      }
    }
    if(y%3==0){
    count+=21-d;
    }else{
      if(m%2==0){
	count+=20-d;
      }else{
	count+=21-d;
      }
    }
    printf("%d\n",count);
  }
return 0;
}