#include<stdio.h>
int main()
{
  int year,month,day;
  int n,result;
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d%d%d",&year,&month,&day);
      result=(1000-year)*(19+20)*5+((999-year)/3+1)*5;
      result-=((month-1)*20+(day-1));
      if(year%3!=0) result+=(month-1)/2;
      printf("%d\n",result);
    }
  return 0;
}