#include <stdio.h>

int eval(int year, int month, int day);

int main(void){
    int n,y,m,d,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d",&y,&m,&d);
        printf("%d\n",eval(1000,1,1)-eval(y,m,d));
    }
    return 0;
}

int eval(int year, int month, int day){
    int days=day-1;
    while(month!=1){
        if((month-1)%2){
            days+=20;
        }else{
            if(year%3){
                days+=19;
            }else{
                days+=20;
            }
        }
        month--;
    }
    while(year!=1){
        if((year-1)%3){
            days+=195;
        }else{
            days+=200;
        }
        year--;
    }
    return days;
}