#20131115

gets.to_i.times{
	days = 1
	y,m,d = gets.split(" ").map{|e|e.to_i}
	#y
	999.downto(y+1){|n|
		days+=20*5+19*5 if n%3!=0
		days+=20*10 if n%3==0
	}
	#m,d
	if y%3 == 0
		days+=20*(10-m)
		days+=20-d
	else
		m=10-m
		days+=20*(m/2)
		days+=19*(m/2+m%2)
		days+=20-d if m%2!=0
		days+=19-d if m%2==0
	end
	

	p days
}