#include<stdio.h>

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

    scanf("%d",&n);

    while(n > 0){
        scanf("%d %d %d", &year, &month, &day);

        int ans = 0;
        if(month % 2 != 0){
            ans += 21 - day;
        }
        else{
            if(year % 3 == 0){
                ans += 21 - day;
            }
            else{
                ans += 20 - day;
            }
        }
        if(month != 10){
            month++;
            if(year % 3 == 0){
                ans += (11 - month) * 20;
            }
            else{
                int i;
                for(i = month; i <= 10; i++){
                    if(i % 2 == 0){
                        ans += 19;
                    }
                    else{
                        ans += 20;
                    }
                }
            }
        }
        year++;
        int i;
        for(i = year; i < 1000; i++){
            if(i % 3 == 0){
                ans += 200;
            }
            else{
                ans += 195;
            }
        }

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

    return 0;
}
