#include<stdio.h>

int main(void){
  int year, month, day;
  int count,counter=0, sum=0;

  scanf("%d", &count);

  while(counter<count){
    int difference_year=0; //1,1,1~(year-1),10,20?????§?????\??°
    int multiple_three=0; //3????????°?????´????????°
    int even_month=0; //??¶??°??????????????°
    int odd_month=0; //?\???°??????????????°

    scanf("%d %d %d", &year, &month, &day);

    multiple_three=(year-1)/3;
    difference_year=multiple_three*200+((year-1)-multiple_three)*195;

    if(year%3==0){ //3????????°?????´??????
      sum=difference_year+(month-1)*20+day;
    }else{
      even_month=(month-1)/2;
      odd_month=month-even_month-1;
      sum=difference_year+even_month*19+odd_month*20+day;
    }

    printf("%d\n", 196471-sum);
    counter++;
  }

  return 0;
}