gets.to_i.times{ s=gets.chomp.chars.map{|c|c.ord-48} n=s.size n.downto(2){|k| 0.upto(k-2){|i| s[i]+=s[i+1] s[i]>9&&s[i]-=9 } } p s[0] }