Three Bit Computer Strikes Back

No attempts yetTime limit1sMemory limit128 MB

Problem

Byteland's scientists have moved on from the Three Bit Computer (TBC) to a new and far more powerful design: the Quantum Three Bit Computer (QTBC). On a quantum machine, initializing the memory is a completely different challenge, because every operation you perform has side effects that influence all of the memory at once.

To cope with this, the scientists use large-scale controlled impulses (LSCI). A single impulse acts on every memory bit at the same time and in exactly the same way, so it can be described by a function f:{0,1,,n1}{0,1,,n1}f : \{0, 1, \ldots, n-1\} \to \{0, 1, \ldots, n-1\}: when impulse ff is emitted, every bit currently in state ss moves to state f(s)f(s). For example, f(3)=5f(3) = 5 means every bit in state 33 becomes state 55.

The scientists can emit kk different impulses f1,f2,,fkf_1, f_2, \ldots, f_k. You may emit them in any order and repeat them as many times as you like; emitting a sequence of impulses applies the corresponding functions one after another to every bit simultaneously.

Determine whether there exists a sequence of impulses that drives every memory bit to state 00, no matter which state each bit started in. In other words, decide whether some composition of the given functions sends every state in {0,1,,n1}\{0, 1, \ldots, n-1\} to 00.

Input

The first line contains a single integer TT (1T101 \le T \le 10), the number of test cases.

Each test case begins with a line containing two integers nn and kk (1n2001 \le n \le 200, 1k51 \le k \le 5), where nn is the number of possible states of a memory bit and kk is the number of available impulses.

Each of the next kk lines describes one impulse: the ii-th of these lines contains nn integers fi(0) fi(1)  fi(n1)f_i(0)\ f_i(1)\ \ldots\ f_i(n-1), separated by single spaces, where each value lies in {0,1,,n1}\{0, 1, \ldots, n-1\}.

Output

For each test case, print a single line containing YES if it is possible to bring every memory bit to state 00, or NO otherwise.