#include <stdio.h>

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

	for ( scanf( "%d", &n ); n--; printf( "%d\n", 196470 - tmp ) ) {
		scanf( "%d %d %d", &y, &m, &d );
		y--;
		m--;

		tmp = y / 3 * 590 + y % 3 * 195 + m * 20 - ( ( y + 1 ) % 3 ? m / 2 : 0 ) + d - 1;
	}

	return 0;
}