Reversing a Snake on a Complete Graph

No attempts yetTime limit1sMemory limit128 MB

Problem

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 MM is a directed path v1,v2,,vMv_1, v_2, \dots, v_M through MM distinct vertices of the complete graph, where v1v_1 is the head and vMv_M is the tail; consecutive vertices are joined by an edge.

A single move works as follows. The head v1v_1 moves to some vertex uu that is currently not occupied by the snake (empty). The whole body then shifts forward by one, the tail cell vMv_M becomes empty, and the snake becomes u,v1,,vM1u, v_1, \dots, v_{M-1}. Because the graph is complete, uu 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,vM1,,v1v_M, v_{M-1}, \dots, v_1 (the starting path read backwards).

For each scenario, decide whether the snake can be reversed.

Input

The first line contains the number of scenarios TT (1T1001 \le T \le 100).

Each scenario follows. A scenario consists of the number of vertices NN (3N1003 \le N \le 100), the snake length MM (2MN2 \le M \le N), and then MM distinct vertex numbers describing the snake from head to tail. Vertices are numbered from 11 to NN.

Output

For each scenario, print on its own line YES if the snake can be reversed, or NO otherwise.