def straddone(s) t = s.dup t.reverse! kuriagari = true (0...t.size).map{|i| tmp = kuriagari kuriagari = 10 <= (t[i].to_i + (kuriagari ? 1 : 0)) t[i] = ((t[i].to_i + (tmp ? 1 : 0)) % 10).to_s } t += '1' if kuriagari t.reverse! end gets.to_i.times{ s = gets.chop a = s.scan(/\d+/) a = a[-1] if a s.sub!(a, straddone(a)) if a puts s }