gets.to_i.times do a, b, c = gets.split.map(&:to_i) min, max = [a, b, c].minmax result = if a == b && b == c if b <= 2 1 else 3 end elsif a == c if a <= 1 -1 else 1 end elsif b == min || b == max 0 elsif b <= 2 -1 else [(a - b).abs + 1, (b - c).abs + 1].min end puts result end