#include <stdio.h>

int main() {

	int n, i, j, k, ans[100] = {0},count = 0;
	int Y[100], M[100], D[100];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &Y[i], &M[i], &D[i]);
	}
	
	for (i = 0; i < n; i++) {
		for (j = Y[i]; j < 1000; j++) {
			if (count == 0) {
				for (k = M[i]; k <= 10; k++) {
					if (j % 3 == 0 || k % 2 == 1)
						ans[i] += 20;
					else
						ans[i] += 19;
				}
			}
			else {
				for (k = 1; k <= 10; k++) {
					if (j % 3 == 0 || k % 2 == 1)
						ans[i] += 20;
					else
						ans[i] += 19;
				}
			}
			count++;
		}
		count = 0;
		
	}

	for (i = 0; i < n; i++)
		printf("%d\n", ans[i] - D[i] + 1);

	return 0;
}