#include <stdio.h>
#define N 100

int main(void){
    int n, i, y, m, d;
    scanf("%d", &n);
    int rest[N] = {};
    for(i = 0; i < n; i++){
        scanf("%d %d %d", &y, &m, &d);
        if(y % 3 == 0){
            rest[i] += (20 - d) + 1;
            rest[i] += (10 - m) * 20;
        }else if(m % 2 == 0){
            rest[i] += (19 - d) ;
            rest[i] += (10 - m) * 39 / 2 + 1;
        }else{
            rest[i] += (20 - d);
            rest[i] += (10 - m) * 39 / 2 + 1;
        }

        if(y % 3 == 0){
            rest[i] += (1000 - y - 1) * 590 / 3;
        }else if(y % 3 == 2){
            rest[i] += (1000 - y - 2) * 590 / 3 + 200;
        }else{
            rest[i] += (1000 - y - 3) * 590 / 3 + 395;
        }
        printf("%d\n", rest[i]);
    }
    return 0;
}
