#include <stdio.h>
#define YEAR 1000
#define MONTH 10
#define DAY_1 20
#define DAY_2 19

int main(void){
    int num,i;
    int num_day;
    int y,m,d;
    scanf("%d",&num);
    for(i=0; i<num; i++){
        num_day = 0;
        scanf("%d %d %d",&y,&m,&d);

        while(y < YEAR){
            while(m <= MONTH){
                if(((y%3)!=0) && ((m%2) == 0)){
                    d++;
                }
                while(d <= DAY_1){
                    num_day ++;
                    d++;
                }
                d = 1;
                m++;

            }
            m = 1;
            y++;
        }
            /*num_day += DAY_1 - d + (m % 2);
            printf("%d\n",num_day);
            if( m == MONTH){//m+1 の処理
                m = 1;
                y++;
            }
            else
            {
                m++;
            }

            if( (m % 2) == 0){
                num_day += DAY_2 ;   
            }
            if( y != YEAR){
                num_day += (MONTH - m)/2 * (DAY_1 + DAY_2);
                y++;
            }
            
            printf("%d\n",num_day);

            num_day += (YEAR - y) % 3 * (5*(DAY_1+DAY_2));
            printf("%d\n",num_day);
            y += (YEAR - y) % 3;

            int year_3 = 2 * (5*(DAY_1+DAY_2)) + (10*(DAY_1));
            num_day += (YEAR - y)/3 * year_3;
*/
            printf("%d\n",num_day);
    }
}
