#include <stdio.h>
#define B 20
#define S 19
int main(){
  int normal_months[] =  {B,S,B,S,B,S,B,S,B,S};
  int special_months[] = {B,B,B,B,B,B,B,B,B,B};
  int i = 0;
  int normal_dates = 0;
  int special_dates = 0;
  while(i != 10){
	normal_dates += normal_months[i];
	i++;
  }
  i = 0;
  while(i != 10){
	special_dates += special_months[i];
	i++;
  }
  int year;
  int month;
  int date;
  scanf("%d", &year);
  while( scanf("%d %d %d", &year, &month, &date) != EOF ){
	int result = 0;
	if(year != 1000){
	  if(year % 3 != 0){
		result += normal_months[month - 1] - date;
		month += 1;
		while(month != 11){
		  result += normal_months[month - 1];
		  month += 1;
		}
	  }else{
		result += special_months[month - 1] - date;
		month += 1;
		while(month != 11){
		  result += special_months[month - 1];
		  month += 1;
		}
	  }
	}
	year += 1;
	while(year != 1000){
	  if(year % 3 != 0){
		result += normal_dates;
	  }else{
		result += special_dates;
	  }
	  year += 1;
	}
	result += 1;
	printf("%d\n", result);
	}
}