#include <stdio.h>

int main(void) {
	int i,n,y,m,d,fp[1024] = {0},dd;
	for(i = 1;i <= 999;i++){
		if(i % 3 == 0){
			fp[i + 1] = fp[i] + 200;
		}
		else{
			fp[i + 1] = fp[i] + 195;
		}
	}
	scanf("%d",&n);
	for(i = 1;i <= n;i++){
		scanf("%d%d%d",&y,&m,&d);
		dd = fp[y];
		if(y % 3 == 0){
			dd+=(20*(m-1));
		}
		else{
			if(m == 2){dd+=20;}
			if(m == 3){dd+=39;}
			if(m == 4){dd+=59;}
			if(m == 5){dd+=78;}
			if(m == 6){dd+=98;}
			if(m == 7){dd+=117;}
			if(m == 8){dd+=137;}
			if(m == 9){dd+=156;}
			if(m == 10){dd+=176;}
		}
		dd+=d;
		printf("%d\n",196471-dd);
	}
	return 0;
}