#include <stdio.h>

int YMday(int y, int m){ //y??´m????????\??°
    if(y%3==0) return 20; //3??§?????????????????´?????§????????????
    else{
        if(m%2!=0) return 20; //??§??????
        else return 19; //?°??????? 
    }
}

int solve(int y, int m, int d){
    int i,ans=0;
    ans = YMday(y,m) - d; // y/m/d??????y/m???????????§?????\??°
    for(i=m+1;i<=10;i++) ans+=YMday(y,i); // y/m+1?????????y??´????????§?????\??°?????????????¨????
    for(i=y+1;i<=999;i++){// 999??´????????§?????\??°????¨????
        if(i%3==0) ans+=200; //3??§?????????????????´?????¨??¨??§??????????????§200??\
        else ans+=195; //3??§????????????????????´???20*5+19*5=195??\
    }
    //???????????§??§y/m/d??????999??´10???????????§?????\??°????±??????£??????
    //?±?????????????1000/1/1????????§????????????1????¶??????????????????????
    return ans+1;
}

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