n = gets.chomp.to_i
n.times do 
    input_data = gets.chomp.split(" ")
    y = input_data[0].to_i
    m = input_data[1].to_i
    d = input_data[2].to_i
    
    x = 1000 - y
    totalY = x * 20 * 10
    # p totalY
    
    count = 0
    (y..1000).each do |i|
        if i % 3 == 0
            count += 1
        end
    end
    # p count
    subY = 1000 - y -count
    subY = subY * 5
    # p subY
    
    x = 0
    if y % 3 != 0
        (1..m - 1).each do |i|
            if i % 2 == 0
                x += 1
            end
        end
    end
    # p x
    
    subM = ((1 - m) * 20) + x
    # p subM
    
    subD = 1 - d
    # p subD
    
    sum = totalY - subY + subM + subD
    p sum
end
