Help me in solving MATDEF problem

My issue

Basic Concepts
Definition of a Matrix

A matrix is a rectangular array of numbers arranged in rows and columns. It’s denoted by a capital letter, such as A, and its elements are represented by a subscript, where the first index denotes the row and the second index denotes the column.
For example:

mat

A is a 3 x 3 matrix. Element
a
23
a
23

is in second row and third column.

Basic Properties and Terminology

Rows, Columns, and Elements: A matrix consists of rows and columns, where each row represents a horizontal arrangement of elements, and each column represents a vertical arrangement of elements. The individual elements of a matrix are the numbers located at the intersection of a specific row and column.
Types of Matrices (based on dimension):
Square Matrix: A matrix with an equal number of rows and columns, i.e., M x M.
Rectangular Matrix: A matrix with different numbers of rows and columns, i.e., M x N
Representation of Matrices

Using 2D Arrays: In programming languages like Python, C++, and Java, matrices are often represented using 2D arrays. Each element in the 2D array corresponds to an element in the matrix, with the first index representing the row and the second index representing the column.

Learning course: RCPIT - 2024 - Matrices
Problem Link: https://www.codechef.com/learn/course/rcpit-fy-matrices/RCPMT01/problems/MATDEF