#include <stdio.h>

int month[]={-99999,20,19,20,19,20,19,20,19,20,19};

int diff(int y,int m,int d){
	int sum=0,i;
	for(i=y+1;i<=999;i++){
		if(i%3==0){
			sum+=200;
		}else{
			sum+=195;
		}
	}
	for(i=m+1;i<=10;i++){
		if(y%3==0){
			sum+=20;
		}else{
			sum+=month[i];
		}
	}
	if(y%3==0)
		sum+=20-d+1;
	else
		sum+=month[m]-d+1;
	return sum;
}

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