#include <stdio.h>

int main( void ) {
	int n, y, m, d, tmp;

	scanf( "%d", &n );
	while ( n-- ) {
		scanf( "%d %d %d", &y, &m, &d );
		y--;
		m--;
		d--;

		tmp = y / 3 * 590 + y % 3 * 195 + d;
		if ( ( y + 1 ) % 3 )
			tmp += m / 2 * 39 + m % 2 * 20;
		else
			tmp += m * 20;

		printf( "%d\n", 196470 - tmp );
	}

	return 0;
}