#include<stdio.h>

int millenium(int, int, int);

void main()
{
	int i, N, y, m, d;
	
	scanf("%d", &N);
	
	for(i = 0; i < N; i++)
	{
		scanf("%d%d%d", &y, &m, &d);
		
		printf("%d\n", millennium(y, m, d));
	}
}

int millennium(int year, int manth, int day)
{
	int result, i;
	
	result = 0;
	
	if(year % 3 == 0)
	{
		result += (10 - manth) * 20 + 20 - day + 1;
	}
	else
	{
		result += 1 - day;
		
		i = 0;
		while((manth + i) < 11)
		{
			result += 19 + (manth + i) % 2;
			
			i++;
		}
	}
	
	i = 1;
	while((year + i) < 1000)
	{
		result += 20 * 10;
		
		if((year + i) % 3 != 0)
		{
			result -= 5;
		}
		
		i++;
	}
	
	return result;
}