This page is still under construction.

Parts of this page are still being built. What you see may change.

Infinite Game

Time limit5sMemory limit128 MB

Summary
Given sets A and B of positive steps taken alternately right and left, decide whether every integer can be reached.
Level

Medium6 of 10

Topics
Number theory, Dynamic programming, Math, Game theory
Solved
No attempts yet

Problem

Sanggeun stands at integer 00 on the number line. He moves using two finite sets of positive integers, AA and BB.

Each move follows these rules:

  • On every odd-numbered move he chooses a number from set AA and steps that many units to the right.
  • On every even-numbered move he chooses a number from set BB and steps that many units to the left.

So the first move uses AA, the second uses BB, the third uses AA again, and so on, alternating between the two sets. On each move he may freely choose any number from the corresponding set.

Write a program that decides whether Sanggeun can reach every integer xx, both positive and negative.

Input

The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500).

Each test case begins with a line containing two integers nn and mm separated by a space (1≤n,m≤10 0001 \le n, m \le 10\,000), where nn is the size of set AA and mm is the size of set BB. The next nn lines each contain one element of AA, and the following mm lines each contain one element of BB. Every element is an integer between 11 and 10910^9, inclusive.

Output

For each test case, print YES on its own line if Sanggeun can reach every integer, and NO otherwise.

Examples4

  1. Example 1

    Input
    2
    1 1
    2
    2
    2 2
    1
    2
    1
    2
    
    Expected output
    NO
    YES
    
  2. Example 2

    Input
    1
    2 2
    2
    3
    2
    3
    
    Expected output
    YES
    
  3. Example 3

    Input
    1
    2 2
    2
    4
    2
    4
    
    Expected output
    NO
    
  4. Example 4

    Input
    1
    2 2
    1
    3
    1
    3
    
    Expected output
    YES