n = gets.to_i

ymd = []
n.times do
	ymd.push(gets.split.map(&:to_i))
end
ymd.each do |ymd_tmp|
	y = ymd_tmp[0]
	m = ymd_tmp[1]
	d = ymd_tmp[2]
	sum = 0
	tmp_y = y
	while tmp_y != 1000
		if tmp_y % 3 == 0 
			sum += 200
		else
			sum += 195
		end
		tmp_y += 1
	end
	sum += 1
	tmp_m = 1
	while tmp_m != m+1   # calcurating border month,becaouse of m+1
		if tmp_m % 2 == 0 && y % 3 != 0
			sum -= 19 
		elsif tmp_m % 2 == 1 && y % 3 != 0
			sum -= 20 
		elsif tmp_m % 2 == 0 && y % 3 == 0
			sum -= 20 
		elsif tmp_m % 2 == 1 && y % 3 == 0
			sum -= 20 
		end
		tmp_m += 1
	end
	if m % 2 == 0 && y % 3 != 0
		sum += 19 - d
	elsif m % 2 == 1 && y % 3 != 0
		sum += 20 - d 
	elsif m % 2 == 0 && y % 3 == 0
		sum += 20 - d
	elsif m % 2 == 1 && y % 3 == 0
		sum += 20 - d
	end
	puts sum
end