#include <stdio.h>

int main(void)
{
    int n;

    scanf("%d", &n);
    while (n--){
        int y, m, d;
        int cnt = 0;

        scanf("%d %d %d", &y, &m, &d);
        while (d != 1){
            d++;
            cnt++;
            if (d > 20 || (d > 19 && y % 3 && m % 2 == 0)){
                d = 1;
                m++;
                if (m > 10){
                    m = 1;
                    y++;
                }
            }
        }
        while (m != 1){
            if (y % 3 && m % 2 == 0) cnt += 19;
            else cnt += 20;
            m++;
            if (m > 10){
                m = 1;
                y++;
            }
        }
        while (y != 1000){
            cnt += y % 3 ? 195 : 200;
            y++;
        }
        printf("%d\n", cnt);
    }

    return 0;
}