/* 
   AOJ 1179
   Millennium
   2015.4.26
 */

int calc(int year, int month, int day)
{
  int days = 0, small_month = 19, large_month = 20, small_year = large_month * 5 + small_month * 5, large_year = large_month * 10, i;

  for(i = year + 1; i < 1000; i++)
    {
      if(i % 3 == 0)
	{
	  days += large_year;
	}
      else
	{
	  days += small_year;
	}
    }
  
  if(year % 3 == 0)
    {
      days += large_month * (10 - month);
      days += large_month - day + 1;
      return days;
    }
  else
    {
      for(i = month + 1; i <= 10; i++)
	{
	  if(i % 2 == 0)
	    {
	      days += small_month;
	    }
	  else
	    {
	      days += large_month;
	    }
	}
  
      if(month % 2 == 0)
	{
	  days += small_month - day + 1;
	}
      else
	{
	  days += large_month - day + 1;
	}
    }

  return days;
}

#include<stdio.h>
int main(void)
{
  int n, i, year, month, day, days_from_birthday;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d %d %d", &year, &month, &day);
      days_from_birthday = calc(year, month, day);
      printf("%d\n", days_from_birthday);
    }
  return 0;
}