#include<stdio.h>
#define rep(i,n) for(int i=0; (i)<(n); i++)
#define normal (20*5+19*5)
#define mod3 (20*10)
#define all (333*(mod3)+666*(normal))
int main(void){
    int n;
    int y,m,d,ans;
    scanf("%d",&n);
    rep(i,n){
        scanf("%d%d%d",&y,&m,&d);
        if(y%3==0){
            ans=d-1+(m-1)*20;
        }
        else{
            ans=d-1;
            for(int i=1;i<m;i++){
                if(i%2==1) ans+=20;
                else ans+=19;
            }
        }
        y=y-1;
        int tmp=y/3;
        ans+=tmp*mod3;
        ans+=(y-tmp)*normal;
        printf("%d\n",all-ans);
    }
}

