10711071 SUSTech Online Judge
Problem 1071 --Binary search tree

1071: Binary search tree

Time Limit: 1 Sec  Memory Limit: 512 MB
Submit: 406  Solved: 179
[Submit][Status][Web Board]


There are a lot of sequences, and each sequence can represent a binary search, please judge whether two sequences can form the same binary search tree.


The first value is the root of the tree, and then you can add the value into the tree following the rules of binary search tree.


The first line will be an integer T, which is the number of test cases. (1 <= T <= 100). For each test case, the first line will be two integers n(1 <= n <= 100) and m(1 <= m <= 63), n is the number of judgement, m is the length of the sequences. The second line will be m integer, a1……am(1 <= ai <= 109), it is the standard sequences. Then followed by n lines, each line will be another arrangement of the standard sequences.


For each judgement, print YES when a arrangement of the standard sequences can form the same binary search tree with the standard sequences, else print NO.

Sample Input

2 6
5 6 7 4 3 2 
5 4 3 2 6 7 
5 7 6 3 4 2

Sample Output