CZ_PROB7 - Put Them on a Circle

An array of numbers ( N1, N2, N3… Nn) is given. The numbers are to be placed on a circle such that the sum of any two adjacent numbers is not divisible by a number in the set of Numbers V1, V2 ,V3...Vk . Write a function, that given N and V determines if such an arrangement exists.

Input

T, the number of test-cases.
For each test case: Input array size of N, 'n' and array size of V, 'k'. This is followed by one line of values of array N (separated by spaces) and then one line of values of array 'V'(separated by spaces).

Output

For each test case print "yes" or "no" on a separate line.

Example

Input:
2
9
3
1 2 3 4 5 6 7 8 9
3 5 7
9
3
1 2 3 4 5 6 7 8 9
1 2 3

Output:
yes
no


Added by:Rahul
Date:2007-03-11
Time limit:1s
Source limit:7000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Dilip Rajeev

hide comments
2018-05-17 00:57:36
Must use backtracking but what is the constraint of this problem ?
2014-01-10 19:08:02 Samil Vargas
i dont know how i lose my time with this easy problem must be deleted.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.