#include <stdio.h>

int main(void){
    int num,sum,i,year,mon,day;
    scanf("%d",&num);
    for(i=0;i<num;i++){
        sum=0;
        scanf("%d %d %d",&year,&mon,&day);
        while(year != 1000){
        if(year % 3 == 0 || mon % 2 != 0){
            sum+=20-day;
        }
        else if(mon % 2 == 0){
            sum+=19-day;
        }
        day=0;
        mon++;
        if(mon == 11){
            mon=1;
            year++;
        }
        }
        printf("%d\n",sum+1);
    }
    return 0;
}