Please help me solving Colorful Grids (ICPC16E)

Hi friends, I recently tried to solve Colorful grids (ICPC16E) in EASY practice section. I am not even getting a hint on how to solve this problem. Please anyone shed some light on this. Thank you.