#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MILL (196470)

int main(){
    int i;
    int n;
    int day;
    int y,m,d;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d %d %d",&y,&m,&d);

        y -= 1;
        m -= 1;
        d -= 1;

        day = 195*y;
        day += (5 * (y/3));
        
        if(m!=0){    
            if((y+1)%3 == 0 && y != 0){
                day += 20*m;
            }else{
                day += 19*m + ((m+1)/2);
            }
        }

        day += d;

        printf("%d\n",MILL-day);
    }


    return 0;
}
