// My Defination
const int MAX_N = 305;
const int MAX_L = 305;
const int MAX_V = 8;
 
int n, m, l;
int a[MAX_L];
int b[MAX_N][MAX_N];
 
bool dp_current[MAX_N][MAX_N];
bool dp_next[MAX_N][MAX_N];
bool dp_can_win[MAX_V][MAX_N][MAX_N];
 
void solve_the_problem(int test_case)
{
    /*
       Please check the value of N :(
       Please read the problem again before coding !
    */
    cin >> l >> n >> m;
 
    for (int i = 1; i <= l; ++i)
    {
        cin >> a[i];
    }
 
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> b[i][j];
        }
    }
 
    for (int i = 0; i <= n; ++i)
    {
        memset(dp_next[i], 0, (m + 1) * sizeof(bool));
    }
 
    for (int k = l; k >= 1; --k)
    {
        memset(dp_can_win, 0, sizeof(dp_can_win));
 
        for (int v = 1; v <= 7; ++v)
        {
            for (int i = n; i >= 0; --i)
            {
                for (int j = m; j >= 0; --j)
                {
                    if (i == n && j == m)
                    {
                        dp_can_win[v][i][j] = false;
                    }
                    else
                    {
                        bool win = false;
                        if (i + 1 <= n && j + 1 <= m)
                        {
                            if (b[i + 1][j + 1] == v && dp_next[i + 1][j + 1] == false)
                            {
                                win = true;
                            }
                        }
                        if (i + 1 <= n)
                        {
                            win = win || dp_can_win[v][i + 1][j];
                        }
                        if (j + 1 <= m)
                        {
                            win = win || dp_can_win[v][i][j + 1];
                        }
                        dp_can_win[v][i][j] = win;
                    }
                }
            }
        }
 
        for (int i = 0; i <= n; ++i)
        {
            for (int j = 0; j <= m; ++j)
            {
                dp_current[i][j] = dp_can_win[a[k]][i][j];
            }
        }
 
        for (int i = 0; i <= n; ++i)
        {
            memcpy(dp_next[i], dp_current[i], (m + 1) * sizeof(bool));
        }
    }
 
    if (dp_current[0][0])
    {
        cout << 'T' << '\n';
    }
    else
    {
        cout << 'N' << '\n';
    }
}
explain the soution for the below problem 
This is the easy version of the problem. The differences between the two versions are the constraints on all the variables. You can make hacks only if both versions of the problem are solved.

Tsovak and Narek are playing a game. They have an array a
 and a matrix b
 of integers with n
 rows and m
 columns, numbered from 1
. The cell in the i
-th row and the j
-th column is (i,j)
.

They are looking for the elements of a
 in turns; Tsovak starts first. Each time a player looks for a cell in the matrix containing the current element of a
 (Tsovak looks for the first, then Narek looks for the second, etc.). Let's say a player has chosen the cell (r,c)
. The next player has to choose his cell in the submatrix starting at (r+1,c+1)
 and ending in (n,m)
 (the submatrix can be empty if r=n
 or c=m
). If a player cannot find such a cell (or the remaining submatrix is empty) or the array ends (the previous player has chosen the last element), then he loses.

Your task is to determine the winner if the players play optimally.

Input
The first line of the input contains t
 (1≤t≤300
) – the number of test cases.

The first line of each test case contains three integers l
, n
, and m
 (1≤l,n,m≤300
) – the size of the array and the sizes of the matrix.

The second line contains l
 integers a1,a2,a3,…al
 (1≤ai≤min(7,n⋅m)
) – the elements of the array a
.

The i
-th of the last n
 lines contains m
 integers bi,1,bi,2,bi,3,…bi,m
 (1≤bi,j≤min(7,n⋅m)
) – representing the i
-th row of the matrix.

It is guaranteed that the sum of n⋅m
 over all test cases does not exceed 105
.

It is guaranteed that the sum of l
 over all test cases does not exceed 300
.

Output
You should output t
 lines, the i
-th of them containing a character representing the answer of the i
-th test case: "T" if Tsovak wins or "N", otherwise (without quotes).