#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;
yea=(999-y)/3*590+((y%3==0)?0:((y%3==1)?395:200));
mon=(10-m)*19+((y%3==0)?(10-m):((11-m)/2));
day=1+(((y%3==0)*(m%2==1))?(20-d):(19-d));
n=yea+mon+day;
return n;
}