#include <stdio.h>

int main(void) {
    int n;
 
    scanf("%d", &n);
    while (n--){
        int y, m, d;
        int cntdays = 0;
 
        scanf("%d %d %d", &y, &m, &d);
        
        for(d=d;d!=1;d++){
            if(y%3 == 0 && d<20)
                cntdays++;
            else if(m%2 == 1 && d<20)
                cntdays++;
            else if (d<19)
                cntdays++;
            else{
                d = 0;
                cntdays++;
                m++;
            }
        }
        
        for(m=m;m!=1;m++){
        	if(m>10){
        	    m=0;
        	    y++;
        	}
        	else if(y%3 == 0)
        	    cntdays+=20;
         	else if(m%2 == 1)
        	    cntdays+=20;
        	else
        	    cntdays+=19;
        }
        
        for(y=y;y!=1000;y++){
        	if(y%3 == 0)
        	    cntdays += 200;
        	else
        	    cntdays += 195;
        }
    
    printf("%d\n", cntdays);
    
    }
    
return 0;
}