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

  int days,y,d,m,mill,n;
  int i;
  
  mill=(1000/3)*200+(1000-(1000/3)-1)*195;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    days=0;
    
    scanf("%d%d%d",&y,&m,&d);

    if(y%3==0){

      days+=((y-1)/3)*200 + (y-(y/3))*195;
      days+=(m-1)*20;
      days+=d-1;

    }else{

      days+=(y/3)*200 + (y-(y/3)-1)*195;
      days+=((m-1)/2)*20 + ((m-1)/2)*19 + ((m-1)%2)*20;
      days+=d-1;

    }

    printf("%d\n",mill-days);

  }

  return 0;

}