#include <stdio.h>
int main(void){
  int n,y,m,d,ans,i,j,k;
  scanf("%d",&n);
  while(n--){
    scanf("%d %d %d",&y,&m,&d);
    ans=0;
    i=y;
    j=m;
    k=d;
    for(;i<1000;i++){
      if(j==11)
	j=1;
      for(;j<11;j++){
	if(k==21)
	  k=1;
	for(;k<21;k++){
	  ans++;
	  if(i%3!=0&&j%2==0&&k==19){
	    k=1;
	    break;
	  }
	}
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}