#include<stdio.h>
int main(){
  int n,i,j;
  int Y,M,D,day;
  int a=196471;

  scanf("%d",&n);
  for(i=0,day=0;i<n;i++,day=0){
    scanf("%d %d %d",&Y,&M,&D);
    for(j=1;j<Y;j++){
      if(j%3==0){
	day+=200;
      }else{
	day+=195;
      }
    }
    for(j=1;j<M;j++){
      if(Y%3==0||j%2==1){
	day+=20;
      }else{
	day+=19;
      }
    }
    day+=D;
    printf("%d\n",a-day);
  }
  return 0;
}