#include<stdio.h>
int main()
{
  int s,n,y,m,d,t,i;

  s=39*5*999+333*5+1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d%d",&y,&m,&d);
    if(m%2==0) t=(y-1)*39*5+((m-1)/2)*20+((m-1)/2)*19+d+5*((y-1)/3);
    else t=(y-1)*39*5+((m-1)/2)*39+d+5*((y-1)/3);
    if(y%3==0)t=t+m/2;
    printf("%d\n",s-t);
  }
  return 0;
}