#include<stdio.h>

main(){
  int n;
  int N[100][3];
  int i,j;
  int allday = 0;
  int ans[100];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&N[i][0],&N[i][1],&N[i][2]);
  }
  
  for(i=1;i<1000;i++){
    if(i%3 == 0){
      allday += 10*20;
    }
    else allday += 5*19 + 5*20;
  }
  allday += 1;
  
  for(i=0;i<n;i++){
    ans[i] = 0;
    for(j=1;j<N[i][0];j++){
    if(j%3 == 0){
      ans[i] += 10*20;
    }
    else ans[i] += 5*19 + 5*20;

    }
    for(j=1;j<N[i][1];j++){
      if(N[i][0]%3 == 0){
	ans[i] += 20;
      }
      else{
	if(j%2 == 0){
	  ans[i] += 19;
	}
	else ans[i] += 20;
      }
    }
    ans[i] += N[i][2];
    printf("%d\n",allday - ans[i]);
  }
  return 0;
}
 