#include<stdio.h>
int main(void){
  int n,y,m,d,count;
  scanf("%d",&n);
  while(n--){
    count=0;
    scanf("%d%d%d",&y,&m,&d);
    count=(y-1)*39*5;
    count+=((y-1)/3)*1*5;
    if(y%3==0){
      count+=(m-1)*20;
    }
    else{
      count+=(m-1)*20-(m-1)/2*1;
    }
    count+=d-1;
    printf("%d\n",196470-count);
  }
  return 0;
}