def f(y, m, d)
	x = 0
	x += (y / 3) * 590
	y %= 3
	if y < 2
		x += y * 195
		x += g(m, d)
	else
		x += 390
		x += h(m, d)
	end
	x
end

def g(m, d)
	x = 0
	x += (m / 2) * 39
	m %= 2
	if m == 0
		x += d
	else
		x += 20 + d
	end
	x
end

def h(m, d)
	20 * m + d
end

n = gets.to_i
millenium = f(999, 0, 0)
n.times {
	y, m, d = gets.split.map &:to_i
	p millenium - f(y-1, m-1, d-1)
}