#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

ll f(ll y,ll m,ll d){
	ll tot=y*195+y/3*5;
	if(y%3==2)tot+=m*20;
	else tot+=m*20-m/2;
	tot+=d;
	return tot;
}

int main(){
	ll n;
	scanf("%lld",&n);
	ll T=f(999,0,0);
	while(n--){
		ll y,m,d;
		scanf("%lld%lld%lld",&y,&m,&d);
		printf("%lld\n",T-f(y-1,m-1,d-1));
	}
}
