/*
AizuOnline A1179
Title millenium
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section

//
int isLeap(int y)
{
  if((y % 3)==0)
    return(1);
  else
    return(0);
}
int day_of_year(int y)
{
  return(195+isLeap(y)*5);
}
int day_of_month(int y,int m)
{
  return(((!isLeap(y)&&(m % 2)==0)?19:20));
}
int datediff(int y1,int m1,int d1,int y2,int m2,int d2)
{
  int i,s;

  if(y1==y2)
   
      if(m1==m2)
	return(d2-d1);
      else
	{
	  s = day_of_month(y1,m1)-d1;
	  if(m2 > m1+1)
	    for(i=m1+1;i<=m2-1;i++)
	      s += day_of_month(y1,i);
	  return(s+d2);
	}
    
  else
    {
      s = datediff(y2,1,1,y2,m2,d2)+1;
      if(y2 > y1+1)
	for(i=y1+1;i<=y2-1;i++)
	  s += day_of_year(i);
      s += datediff(y1,m1,d1,y1,10,day_of_month(y1,10));
      return(s);
    }
}
main()
{
  int y1,m1,d1,ret,n,i;
  //printf("2001=%d\n",isLeap(2001));
  scanf("%d ",&n);
    
  for(i=0;i<n;i++)
    {
      scanf("%d %d %d ",&y1,&m1,&d1);
      ret=datediff(y1,m1,d1,1000,1,1);
      printf("%d\n",ret);
    }
    
  return(0);
}