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,…,n−1}→{0,1,…,n−1}: when impulse f is emitted, every bit currently in state s moves to state f(s). For example, f(3)=5 means every bit in state 3 becomes state 5.
The scientists can emit k different impulses f1,f2,…,fk. 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 0, 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,…,n−1} to 0.
The first line contains a single integer T (1≤T≤10), the number of test cases.
Each test case begins with a line containing two integers n and k (1≤n≤200, 1≤k≤5), where n is the number of possible states of a memory bit and k is the number of available impulses.
Each of the next k lines describes one impulse: the i-th of these lines contains n integers fi(0) fi(1) … fi(n−1), separated by single spaces, where each value lies in {0,1,…,n−1}.
For each test case, print a single line containing YES if it is possible to bring every memory bit to state 0, or NO otherwise.