#include <stdio.h>

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

	scanf( "%d", &n );

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

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

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

	return 0;
}