#include<stdio.h>

int main(void)
{
	int n;
	int y,m,d;
	int i,j,k,l;
	int day;
	
	scanf("%d",&n);
	for(l=0;l<n;l++)
	{
		scanf("%d %d %d",&y,&m,&d);
		day = 0;
		j = m;
		k = d;
		for(i=y;i<1000;i++)
		{
			for(;j<=10;j++)
			{
				if(i%3==0)
				{
					for(;k<=20;k++)
					{
						day++;
					}
				}
				else
				{
					if(j%2==0)
					{
						for(;k<=19;k++)
						{
							day++;
						}
					}
					else
					{
						for(;k<=20;k++)
						{
							day++;
						}
					}
				}
				k = 1;
			}
			j = 1;
		}
	printf("%d\n",day);
	}
	return 0;
}