시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
5 초 128 MB 22 4 3 33.333%

문제

상근이는 지난 밤에 술을 많이 마셨고, 지금 학교 근처를 배회하고 있다. 상근이는 술에 취하면, 두 집합 A와 B를 이용해서 움직인다. A와 B는 크기가 유한인 양의 정수의 부분 집합이다.

상근이는 지금 0에 서있다. 이동할 때, A에서 수 하나를 골라서 그 숫자만큼 오른쪽으로 걷거나, B에서 수 하나를 골라서 그만큼 왼쪽으로 걸어간다. 홀수번째에는 수를 A에서 고르고, 짝수번째에는 B를 고른다음에 움직인다.

과연 상근이가 모든 정수 x(양수, 음수 모두)에 도달할 수 있는지 아닌지를 구하는 프로그램을 작성하시오.

입력

첫째 줄에 테스트 케이스의 수 t가 주어진다. (1 ≤ t ≤ 500) 다음 줄에는 각 테스트 케이스가 주어진다.

테스트 케이스의 첫째 줄에는 두 정수 n과 m이 공백으로 구분되어져 있다. (1 ≤ n, m ≤ 10,000) n은 집합 A의 크기, m은 집합 B의 크기이다. 다음 n개 줄에는 집합 A의 원소가, m개 줄에는 집합 B의 원소가 한 줄에 하나씩 순서대로 주어진다. 집합에 들어있는 수는 모두 1보다 크거나 같고, 109보다 작거나 같다.

출력

각 테스트 케이스에 대해서, 상근이가 모든 정수에 도달할 수 있으면 YES를, 아니면 NO를 한 줄에 하나씩 출력한다.

예제 입력 1

2
1 1
2
2
2 2
1
2
1
2

예제 출력 1

NO
YES
W3sicHJvYmxlbV9pZCI6Ijc2MjMiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJiMzRcdWQ1NWMgXHVhYzhjXHVjNzg0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWMwYzFcdWFkZmNcdWM3NzRcdWIyOTQgXHVjOWMwXHViMDljIFx1YmMyNFx1YzVkMCBcdWMyMjBcdWM3NDQgXHViOWNlXHVjNzc0IFx1YjljOFx1YzE2OFx1YWNlMCwgXHVjOWMwXHVhZTA4IFx1ZDU1OVx1YWQ1MCBcdWF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