#include<stdio.h>

int main(void)
{
  int n, year, month, day, i, j, ans[100]={0};
  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf(" %d %d %d",&year, &month, &day);
    for(j=month; j<=10; j++) { //初めの年
      if(j==month) {    //初めの月
	if(year%3==0||j%2==1){
	  ans[i]+=21-day;
	}
	else{
	  ans[i]+=20-day;
	}
      }
      else{
	if(year%3==0||j%2==1){
	  ans[i]+=20;
	}
	else{
	  ans[i]+=19;
	}
      }
    }

    for(j=year+1; j<1000; j++){
      if(j%3==0){
	ans[i]+=20*10;
      }
      else{
	ans[i]+=19*5+20*5;
      }
    }
  }
  for(i=0; i<n; i++){
    printf("%d\n", ans[i]);
  }



  return 0;
}