#include <stdio.h>
#include <string.h>
int main()
{
    int a;
    scanf("%d",&a);
    int ans[a];
    int i=0;
    int flag=a;
    while(a--)
    {
        i++;
        int ye,mth,dy;
        scanf("%d %d %d",&ye,&mth,&dy);
        int sum=0;
        if(ye%3==1){
            sum+=dy;
            if(mth==1)  sum+=0;
            else if(mth%2==0)    sum+=( (mth/2)*20 + (mth-(mth/2)-1)*19 );
            else sum+=(mth/2*20 + (mth-(mth/2)-1)*19 );
            sum+=590*(ye/3);
        }
        if(ye%3==2){
            sum+=590*(ye/3)+195;
            if(mth==1)  sum+=0;
            else if(mth%2==0)    sum+=( (mth/2)*20 + (mth-(mth/2)-1)*19 );
            else sum+=(mth/2*20 + (mth-(mth/2)-1)*19 );
            sum+=dy;
        }
        if(ye%3==0){
            if(ye==3)   sum+=390;
            else    sum+=590*(ye/3-1)+390;
            sum+=(mth-1)*20;
            sum+=dy;
        }
        ans[i]=sum;
    }
    for ( int i=1 ; i<=flag ; i++ )
        printf("%d\n",196471-ans[i]);
}