def process(s) s = s.chars.map(&:to_i) while s.size > 1 s = s.each_cons(2).map{|a,b| a + b >= 10 ? a + b - 9 : a + b } end s[0] end T = gets.to_i puts T.times.map{ process(gets.chomp) }