#include <stdio.h>
#include <stdlib.h>
int month[10] = {20,19,20,19,20,19,20,19,20,19};
int daycount(int *y,int *m,int *d);
int main(void){
	int *y, *m, *d;
	int n, i, mir;
	int Y = 1000, M = 1, D = 1;
	scanf("%d",&n);
	mir = daycount(&Y,&M,&D);
	y = (int *)malloc(sizeof(int) * n);
	m = (int *)malloc(sizeof(int) * n);
	d = (int *)malloc(sizeof(int) * n);
	for(i = 0;i < n;i++)
		scanf("%d %d %d",y + i,m + i,d + i);
	for(i = 0;i < n;i++)
		printf("%d\n",mir - daycount(y + i,m + i,d + i));
	return 0;
}
int daycount(int *y,int *m,int *d){
	int sum = 0,i , j;
	for(i = 0;i < *y - 1;i++){
		if((i + 1) % 3 == 0)
			sum += 200;
		else{
			for(j = 0;j < 10;j++)
				sum += month[j];
		}
	}
	for(i = 0;i < *m - 1;i++){
		if(*y % 3 == 0)
			sum += 20;
		else
			sum += month[i];
	}
	sum += *d;
	return sum;
}