/*
#include<stdio.h>

//1000.1.1=590*333=196470

int main(void){
	int n,y,m,d,i,l,j;
	long ans;
	FILE *fin,*fout;
	
	fin=fopen("A.txt","r");
	fout=fopen("Aans.txt","w");
	
	fscanf(fin,"%d",&n);
	
	for(;n>0;n--){
		fscanf(fin,"%d %d %d",&y,&m,&d);
		ans=0;
		while(y>3){
			y-=3;
			ans+=590;
		}
		if(y==2)ans+=195;
		else if(y==3)ans+=390;
		
		ans+=(m-1)*19+d+(m-1)/2;
		if(m%2==1)ans--;
		if(y==3)ans+=(m-1)/2;
		j=590*333;
		fprintf(fout,"%ld\n",j-ans);
		
	}
	
	return 0;
}
*/

#include<stdio.h>

int main(void){
	int y,m,d,i,l,n,ans;
	FILE *fin,*fout;
	
	fin=fopen("a.txt","r");
	fout=fopen("Aans,txt","w");
	
	fscanf(fin,"%d",&n);
	
	for(;n>0;n--){
		fscanf(fin," %d %d %d",&y,&m,&d);
		ans=0;
		while(y>3){
			y-=3;
			ans+=590;
		}
		for(i=1;i<m;i++){
			ans+=19;
			if(i%2==1)ans+=1;
		}
		ans+=d;
		
		fprintf(fout,"%d\n",333*590-ans);
	}
	return 0;
}
		
		
	