#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,n,mi,misum = 0,y,m,d;
    
    mi = 196470;
    
    
    
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        
        scanf("%d %d %d",&y,&m,&d);
        
        misum += (y-1) * 195;
        misum += (((y-1)/3)) * 5;
        
    
        misum += (m-1) * 20;
        
        if (y%3 != 0) {
        
            misum -= (m-1)/2*1;
        
        }
        
        
        misum += d-1;

        printf("%d\n",mi-misum);
        misum = 0;
        
    }
    return 0;
}