#include<stdio.h>

int main(void){
    
    int n, i, j, day;
    int y[101], m[101], d[101];
    
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&y[i]);
        scanf("%d",&m[i]);
        scanf("%d",&d[i]);
    }
    
    for(i=1;i<=n;i++){
        day = 0;
        if(y[i]%3==0)  day += (21 - d[i]);
        else if(m[i]%2==0) day += (20 - d[i]);
        else day += (21 - d[i]);
        
        for(j=m[i]+1;j<=10;j++){
            if(y[i]%3==0) day += 20;
            else if(j%2==0) day += 19;
            else day += 20;
        }
        
        for(j=y[i]+1;j<=999;j++){
            if(j%3==0) day+= 200;
            else day += 195;
        }
        
        printf("%d\n",day);
    }
    
    return 0;
}
