#include<stdio.h>
#include<stdlib.h>

int mil(int y, int m, int d) {

	int year=((y-1)/3)*200+(y-1-(y-1)/3)*195;
	int month;

	if(y%3==0)
		return year+(m-1)*20+d;
	else {
		if(m%2==0) {
			month=(m/2-1)*19+(m/2)*20;
			return year+month+d;
		}
		else {
			month=(m/2)*19+(m/2)*20;
			return year+month+d;
		}

	}
}

int main() {

	int n;
	int *y,*m,*d,*answer;
	int i;

	scanf("%d",&n);
	y=(int *)malloc(n * sizeof(int));
	m=(int *)malloc(n * sizeof(int));
	d=(int *)malloc(n * sizeof(int));
	answer=(int *)malloc(n * sizeof(int));

	for(i=0;i<n;i++) {
		scanf("%d %d %d",&y[i],&m[i],&d[i]);
		answer[i]=mil(1000,1,1)-mil(y[i],m[i],d[i]);
	}

	for(i=0;i<n;i++)
		printf("%d\n",answer[i]);

	free(y);
	free(m);
	free(d);
	free(answer);

	return 0;
}