#include <stdio.h>
#define USUAL_DAYS_OF_YEAR 195
#define UNUSUAL_DAYS_OF_YEAR 200
#define DAYS_OF_THREEYEARS 590
#define DAYS_OF_SMONTH 19
#define DAYS_OF_LMONTH 20


long CntDay(int y,int m,int d);

int main(){
 int n,i,Year,Month,Day;
 scanf("%d\n",&n);
 i=1;
 while(i<=n){
  scanf("%d %d %d",&Year,&Month,&Day);
  printf("%ld\n", CntDay(Year,Month,Day));
  i++;
 }
 return 0;
}

long CntDay(int y,int m,int d){

long yea,mon,day;
yea=(999-y)/3*DAYS_OF_THREEYEARS+((y%3==0)?0:((y%3==1)?(USUAL_DAYS_OF_YEAR+UNUSUAL_DAYS_OF_YEAR):UNUSUAL_DAYS_OF_YEAR));
mon=(10-m)*DAYS_OF_SMONTH+((y%3==0)?(10-m):((11-m)/2));day=((y%3==0)||(d%2==1))?(DAYS_OF_LMONTH-d):(DAYS_OF_SMONTH-d);
return (yea+mon+day);
}