#include <stdio.h>

int main(void) {
	int d_num,cur_d;
	int y,m,d;
	int count;
	scanf("%d",&d_num);
	for(cur_d=0;cur_d<d_num;cur_d++) {
		scanf("%d%d%d",&y,&m,&d);
		for(count=0;y<1000;count++) {
			d++;
			if(d>20 || (d==20 && y%3!=0 && m%2==0)) {
				d=1;
				m++;
				if(m>10) {
					m=1;
					y++;
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}