#include <stdio.h>

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 n,yea,mon,day;
if(y%3==0){
yea=(999-y)/3*590;
} else if(y%3==1){
yea=(999-y)/3*590+395;
} else {
yea=(999-y)/3*590+200;
}
if(y%3==0){
mon=(10-m)*20;
} else {
mon=(10-m)*19+(10-m)/2;
}
if ((y%3==0)||(m%2==1)){
day=1+(20-d);
} else {
day=1+(19-d);
}

n=yea+mon+day;
return n;
}