You are provided with a grid of pixels and the task is to reach at all the four corners from a single pixel inside the grid, covering the minimum number of pixels. One is allowed to move in eight directions as is shown in Fig. 1, if a connection is available. Write an algorithm to generate all the four paths.

For example, let there be a 5×85×8 grid and we have to start from pixel number 2020. All the pixels are numbered in row-wise manner starting from '1', as is shown in Fig. 2. The required sequences of pixels to be followed so as to reach each of the four corners are marked in Fig. 2.

You have to develop and implement the algorithm that will produce the four paths from the given starting pixel.