How to solve Make the Matrix Beautiful from July Cook-Off 2021?

Hi, what is the approach to solve MATBEAUT from July Cook-Off 2021?

I have a solution of exponential time complexity using recursion, trying out all possible scenarios. Not able to find any editorial for this problem.

Thank you.

editorial link