#include <stdio.h>

int n;
int memo[1000][11][21]={0};

int main(void){
  int i,j,k,t,co=0,max;
  for(i=1;i<=999;i++){
    for(j=1;j<=10;j++){
      if(i%3==0||j%2!=0)max=20;
      else max =19;
	for(k=1;k<=max;k++){
	  memo[i][j][k]=co;
	  co++;
	}
    }
  }
  scanf("%d",&n);
  for(t=0;t<n;t++){
    scanf("%d%d%d",&i,&j,&k);
    printf("%d\n",196470-memo[i][j][k]);
  }
  
	
  return 0;
}
