Codeforces Round 972 (Div. 2)
E1
Subtangle Game (Easy Version)
Codeforces
2100
原题
← DE2 →
翻译中…

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 \le t \le 300$) – the number of test cases.

翻译中…

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

翻译中…

The second line contains $l$ integers $a_1, a_2, a_3, \ldots a_l$ ($1 \le a_i \le \min(7, n \cdot m)$) – the elements of the array $a$.

翻译中…

The $i$-th of the last $n$ lines contains $m$ integers $b_{i,1}, b_{i,2}, b_{i,3}, \ldots b_{i,m}$ ($1 \le b_{i,j} \le \min(7, n \cdot m)$) – representing the $i$-th row of the matrix.

翻译中…

It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $10^5$.

翻译中…

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).

翻译中…

Note

翻译中…

In the first example, Tsovak starts by looking for $1$. There is only one occurrence of $1$ at $(1,1)$, so he chooses it. Then Narek needs to look for $2$ in the submatrix of $(2, 2)$, which consists of just the last two elements: $5$ and $2$. He chooses $2$, and then Tsovak loses since the array has ended.

翻译中…

In the second example, Tsovak needs to choose $1$. There is a $1$ at the cell $(n,m)$, so he chooses that cell. Then, since the submatrix of $(n + 1, m + 1)$ is empty, Narek cannot find $2$, so he loses.

翻译中…

样例

Input #1
3
2 2 3
1 2
1 3 5
4 5 2
2 2 4
1 2
1 1 3 2
4 2 5 1
2 4 2
1 2
3 4
5 5
5 5
5 5
Output #1
N
T
N
InputCopy OutputCopy
题目信息
题号
2005E1
时间限制
2 s
内存限制
256 MB
标签
动态规划
博弈论
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。