#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int y,m,d;
    scanf("%d%d%d",&y,&m,&d);
    int answer=1;
    for(int j=y;j<1000;j++){
      if(j%3){
        answer+=195;
      }else{
        answer+=200;
      }
    }
      if(y%3){
        for(int k=1;k<m;k++){
          if(m%2){
            answer-=20;
          }else{
            answer-=19;
          }
        }
      }else{
        for(int k=1;k<m;k++){
          answer-=20;
        }
      }
      
        
      
      answer-=d;
      printf("%d\n",answer);
  }
}
