#include<stdio.h>

int output(int y,int m,int d){

  int i,count=0;

  for(i=1;i<y;i++){

    if(i%3==0){
      count+=200;
    }else{
      count+=195;
    }
  }

  for(i=1;i<m;i++){

    if(y%3==0){
      count+=20;
    }else{
      if(i%2==0){
	count+=19;
      }else{
	count+=20;
      }
    }
  }

  for(i=1;i<=d;i++){

    count++;
  }

  return(count);
}

int main(void){

  int n,millennium,i,a,b,c;

  scanf("%d",&n);

  millennium=output(1000,1,1);

  printf("%d\n",millennium);

  for(i=0;i<n;i++){
    
    scanf("%d",&a);scanf("%d",&b);scanf("%d",&c);
    printf("%d\n",millennium-output(a,b,c));
  }

  return(0);
}