A game company decided to build a new version of the classic game Snake, played on a complete graph. A complete graph is a graph in which every two distinct vertices are joined by an edge.
In this game a snake of length M is a directed path v1,v2,…,vM through M distinct vertices of the complete graph, where v1 is the head and vM is the tail; consecutive vertices are joined by an edge.
A single move works as follows. The head v1 moves to some vertex u that is currently not occupied by the snake (empty). The whole body then shifts forward by one, the tail cell vM becomes empty, and the snake becomes u,v1,…,vM−1. Because the graph is complete, u may be any currently empty vertex. (The head may not move onto a vertex occupied by the body or the tail.)
A mathematician proved that if the snake can be reversed in finitely many moves — that is, made to occupy exactly the same edges while the head and the tail swap places — then this is equivalent to being able to reach any arrangement of the snake on the graph. Testing the game therefore reduces to deciding, for a given starting arrangement, whether the snake can be reversed.
Reversing the snake means performing moves until the snake becomes vM,vM−1,…,v1 (the starting path read backwards).
For each scenario, decide whether the snake can be reversed.
The first line contains the number of scenarios T (1≤T≤100).
Each scenario follows. A scenario consists of the number of vertices N (3≤N≤100), the snake length M (2≤M≤N), and then M distinct vertex numbers describing the snake from head to tail. Vertices are numbered from 1 to N.
For each scenario, print on its own line YES if the snake can be reversed, or NO otherwise.