#include<stdio.h>

#define LONG_MONTH 20   
#define SHORT_MONTH 19  
#define LIMIT 100     

int main() {
    
    int n;                      
    int year[LIMIT];       
    int month[LIMIT];    
    int day[LIMIT];        
    int number_of_days[LIMIT];  
    int i;                      
    int years, months;      

    
    int common_year = 5 * LONG_MONTH + 5 * SHORT_MONTH;
    
    int multiples_of_3 = 10 * LONG_MONTH;
    
   
    years = (1000-1) / 3;  
    int millennium = years * multiples_of_3 + ((1000-1)-years) * common_year + 1;
    
    
    scanf("%d", &n);  
    for (i = 0; i < n; i++) {
        scanf("%d  %d  %d", &year[i], &month[i], &day[i]);
        
       
        number_of_days[i] += day[i];
        years = (year[i]-1) / 3;  
        number_of_days[i] += years * multiples_of_3 + (year[i]-1-years) * common_year;
        if (year[i] % 3 == 0) {
            number_of_days[i] += (month[i]-1) * 20;
           
        }
        else {
            months = (month[i]-1) / 2; 
            number_of_days[i] += months * SHORT_MONTH + (month[i]-months-1) * LONG_MONTH;
        }
    }
    for (i = 0; i < n; i++) {
        printf("%d\n", millennium - number_of_days[i]);
    }
    
    return 0;
}