# frozen_string_literal: true in_h, in_w = gets.chomp.split.map(&:to_i) in_s = in_h .times .map do line = gets.chomp.chars new = +"" until line.empty? c = line.shift if c == "9" line.shift(5) new << "9Yiwiy" elsif c == "y" line.shift(5) new << "yiwiY9" else new << "." end end new end .join("\n") .chomp puts in_s