rowProduct and colProduct, to store the prefix products for rows and columns respectively.rowProduct.rowProduct.colProduct.p with the same dimensions as grid.p[i][j] in the result matrix, calculate the product of rowProduct[i] and colProduct[j], excluding the current element grid[i][j], and take the modulo 12345.p.