#include<stdio.h>
long n,i,j,ans,year,month,day;
int main(void)
{
  scanf("%d",&n);
  for (i=1;i<=n;i++)
  {
    ans=0;
    scanf("%d%d%d",&year,&month,&day);
    if ((year%3==0)||(month%2==1)) ans=ans+21-day;else ans=ans+20-day;
    month=month+1;
    if (month<=10)
    {
      for (j=month;j<=10;j++)
        if ((year%3==0)||(j%2==1)) ans=ans+20;else ans=ans+19;
    }
    year=year+1;
    for (j=year;j<=999;j++)
      if (j%3==0) ans=ans+200;else ans=ans+195;
    printf("%d\n",ans);
  }
  return 0;
}   