def calc(t)
    t[0] -= 1
    t[1] -= 1
    t[2] -= 1
    ret = 590 * (t[0]/3)
    t[0] %= 3
    ret += t[0] * 195
    if t[0] == 2
        ret += 20 * t[1]
        ret += t[2]
    else
        even = false
        while t[1] > 0
            ret += 19
            ret += 1 if !even
            even = !even
            t[1] -= 1
        end
        ret += t[2]
    end
    return ret
end
n = gets.to_i
t = n.times.map{gets.split.map(&:to_i)}
mil = calc([1000,1,1])
t.each do |tt|
    puts mil - calc(tt)
end