#include <stdio.h>

int main(){
	int count,counter;
	int y,m,d;
	int sum;
	
	scanf("%d",&count);
	counter=0;
	while(counter<count){
		scanf("%d %d %d",&y,&m,&d);
		sum=(y-1)*(20+19)*5+((y-1)/3)*5+d;
		if(y%3==0){
			sum+=(m-1)*20;
		}else{
			sum+=(m-1)*19+m/2;
		}
		printf("%d\n",196471-sum);
		counter++;
	}
	return 0;
}