#include <stdio.h> 

#define N 100

#define TEN 10
#define BIG 20
#define SMALL 19
#define YEAR 195
#define YEAR3 200

int convert(int y,int m,int d){
    int day=0;
    int i;

    for(i=1;i<y;i++){
        if(i%3==0){
            day += YEAR3;
        } else {
            day += YEAR;
        }
    }

    if(y%3==0){
        day += BIG * (m-1);
    } else {
        for(i=1;i<m;i++){
            if(i%2==0){
                day += SMALL;
            } else {
                day += BIG;
            }
        }
    }

    day += d;
    return day;
}

int main(void){
    int n;
    int ymd[N][4]={{}};
    int daymil;

    daymil = convert(1000,1,1);

    scanf("%d",&n);

    int i;
    for(i=0;i<n;i++){
        scanf("%d%d%d",&ymd[i][0],&ymd[i][1],&ymd[i][2]);
        ymd[i][3] = daymil;
        ymd[i][3] -= convert(ymd[i][0],ymd[i][1],ymd[i][2]);
        printf("%d\n",ymd[i][3]);
    }

    return 0;
}
