#include<stdio.h>
int main(){
  int n,yy,y,m,d,d3,ans,i;
  d3=(20+19)*15+5;
  scanf("%d",&n);
  while(n--){
    scanf("%d %d %d",&y,&m,&d);
    yy=1000-y;
    ans=yy/3*d3;
    if(yy%3)ans+=yy%3*(39*5)+5;
    if(y%3){
      for(i=1;i<m;i++)ans-=19+i%2;
      ans-=d-1;
    }
    else ans-=20*(m-1)+d-1;
    printf("%d\n",ans);
  }
  return 0;
}