#include<stdio.h>
void AoD(int year,int month,int day);
int main(void){
  int y,m,d,i,data;

  scanf("%d",&data);
  for(i=1;i<=data;i++){
    scanf("%d %d %d",&y,&m,&d);
    AoD(y,m,d);
  }
}
void AoD(int year,int month,int day){
  int i,count;

  if(year%3==0)
    count = 20-day;
  else if(month%2!=0)
    count = 20-day;
  else
    count = 19-day;

  if(year%3==0)
    count += (10-month)*20;
  else if(month%2!=0)
    count += 19 + (10-month+1)/2*39;
  else
    count += (10-month)/2*39;

  if(year%3==0)
    count += (999-year)/3*580;
  else if(year%3==1)
    count += 390 + (999-year+2)/3*580;
  else 
    count += 195 + (999-year+1)/3*580;

  count++;

  printf("%d\n",count);
}