def evaluate(str) arr = str.split arr = [arr[0], arr[2], arr[4]] ink = -1 3.times { |i| ink = i if arr[i] =~ /machula/ } result = arr[2].to_i - arr[1].to_i if ink == 0 result = arr[2].to_i - arr[0].to_i if ink == 1 result = arr[0].to_i + arr[1].to_i if ink == 2 return str if ink == -1 casti = arr[ink].split /machula/ casti.unshift "" if arr[ink][0,7] == "machula" and casti.length < 2 casti.push "" if casti.length < 2 riesenie = result.to_s[(casti[0].length...result.to_s.length-casti[1].length)] str.sub /machula/, riesenie end num_cases = gets.to_i num_cases.times do gets # empty line puts(evaluate(gets.strip)) end