Rolling a Cube
A cube with a face size of 1×1 is placed on an n×m grid where each cell contains a random number from 0 to 9. We want to roll the cube on this grid.
Initially, each face of the cube has the number 0 written on it, and the numbers on the grid and the cube change according to the following rules: