#include <stdio.h>

int calc(int y, int m, int d) {
    int x = 0;
    if (y % 3 == 0 || m % 2 != 0)
	x = 21 - d;
    else
	x = 20 - d;
    for (int i = m + 1; i < 11; i++) {
	if (y % 3 == 0 || i % 2 != 0)
	    x += 20;
	else
	    x += 19;
    }
    for (int i = y + 1; i < 1000; i++) {
	if (i % 3 == 0)
	    x += 200;
	else
	    x += 195;
    }
    return x;
}

int main(void) {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
	int y, m, d;
	scanf("%d%d%d", &y, &m, &d);
	printf("%d\n", calc(y, m, d));
    }
    return 0;
}