#include <stdio.h>

#define MILLENNIUM 1000
#define y_days(year) ((year)%3? 195: 200)
#define m_days(year, month) ((year)%3? (month)%2? 20: 19: 20)

int main(void)
{
    int year, month, day, n, i, res;

    scanf("%d", &n);

    while(n--)
    {
        /* init, input */
        res = 0;
        scanf("%d %d %d", &year, &month, &day);

        /* count */
        for(i=year+1; i<MILLENNIUM; i++) res += y_days(i);
        for(i=month+1; i<=10; i++) res += m_days(year, i);
        res += m_days(year, month) - day + 1;

        /* print */
        printf("%d\n", res);
    }

    return 0;
}