#include<stdio.h>

int main(void){
	int y,m,d,i,l,n,ans;
	
	scanf("%d",&n);
	
	for(;n>0;n--){
		scanf(" %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;
		
		printf("%d\n",333*590-ans);
	}
	return 0;
}
		
		
	