#include <stdio.h>

int main(void)
{
  int x, i, k, y, m, d, Y = 0, M = 0 ,M1 = 0, D = 0, date = 0, Y1 = 0;
  scanf("%d",&x);
  
 
  date = 0;
  for(i = 0 ; i < x ; i++){
    scanf("%d",&y);
    scanf("%d",&m);   
    scanf("%d",&d);
  
    Y = y;
    M = 10 - m;
    D = 21 - d;
    M1 = 0;
  if(Y%3 == 0){
    M1 = M * 20;
  }
  else if(Y%3 != 0){
    for(k = M ; k > 0 ; k--){
      if(k%2 != 0){
       M1 += M * 20;
     } 
      else if(k%2 == 0){
       M1 += M * 19;
     } 
    }
  }
  
  Y = 1000 - Y;
  Y = Y - 1;
  Y1 = 0;
  
  for( ;Y > 0 ; Y--){
    if(Y%3 == 0){
      Y1 += 200;
    }
    else if(Y%3 != 0){
      Y1 += 195;
    }
  }
 
  date = Y1 + M1 + D;
  printf("%d\n",date);
  date = 0;
}


  
  return 0;
}