Bakry faced a problem, but since he's lazy to solve it, he asks for your help.

You are given a tree of $n$ nodes, the $i$-th node has value $a_i$ assigned to it for each $i$ from $1$ to $n$. As a reminder, a tree on $n$ nodes is a connected graph with $n-1$ edges.

You want to delete at least $1$, but at most $k-1$ edges from the tree, so that the following condition would hold:

For every connected component calculate the bitwise XOR of the values of the nodes in it. Then, these values have to be the same for all connected components.

Is it possible to achieve this condition?


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ $(1 \leq t \leq 5 \cdot 10^4)$. Description of the test cases follows.

The first line of each test case contains two integers $n$ and $k$ $(2 \leq k \leq n \leq 10^5)$.

The second line of each test case contains $n$ integers $a_1, a_2, ..., a_n$ $(1 \leq a_i \leq 10^9)$.

The $i$-th of the next $n-1$ lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i\neq v_i$), which means that there's an edge between nodes $u_i$ and $v_i$.

It is guaranteed that the given graph is a tree.

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, you should output a single string. If you can delete the edges according to the conditions written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).

You can print each letter of "YES" and "NO" in any case (upper or lower).


-----Examples-----

Input
5
2 2
1 3
1 2
5 5
3 3 3 3 3
1 2
2 3
1 4
4 5
5 2
1 7 2 3 5
1 2
2 3
1 4
4 5
5 3
1 6 4 1 2
1 2
2 3
1 4
4 5
3 3
1 7 4
1 2
2 3
Output
NO
YES
NO
YES
NO


-----Note-----

It can be shown that the objection is not achievable for first, third, and fifth test cases.

In the second test case, you can just remove all the edges. There will be $5$ connected components, each containing only one node with value $3$, so the bitwise XORs will be $3$ for all of them.

In the fourth test case, this is the tree:

.

You can remove an edge $(4,5)$

The bitwise XOR of the first component will be, $a_1 \oplus a_2 \oplus a_3 \oplus a_4 = 1 \oplus 6 \oplus 4 \oplus 1 = 2$ (where $\oplus$ denotes the bitwise XOR).

The bitwise XOR of the second component will be, $a_5 = 2$.

Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Graph algorithms

Graph traversal

Constructive algorithms

Tree algorithms

Dynamic programming
Skill types: Dynamic programming

Bit manipulation

Starter code:

Solutions:
import sys
from collections import deque
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	arr = [0] + list(map(int, input().split()))
	graph = [[] for _ in range(n + 1)]
	ind = [0] * (n + 1)
	val = [0] * (n + 1)
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		graph[u].append(v)
		graph[v].append(u)
		ind[u] += 1
		ind[v] += 1
	qu = deque()
	V = 0
	for i in range(1, n + 1):
		V ^= arr[i]
		if ind[i] == 1:
			qu.append(i)
	if V == 0:
		return 'YES'
	if k < 3:
		return 'NO'
	nums = 0
	while qu:
		curr = qu.popleft()
		val[curr] ^= arr[curr]
		if val[curr] == V:
			nums += 1
		for nei in graph[curr]:
			ind[nei] -= 1
			if val[curr] != V:
				val[nei] ^= val[curr]
			if ind[nei] == 1:
				qu.append(nei)
	return 'YES' if nums >= 2 else 'NO'
for _ in range(int(input())):
	print(solve())


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	X = 0
	for i in a:
		X ^= i
	g = [[] for i in range(n)]
	for i in range(n - 1):
		(u, v) = map(int, input().split())
		g[u - 1].append(v - 1)
		g[v - 1].append(u - 1)
	if X == 0:
		print('YES')
		return
	elif k == 2:
		print('NO')
		return
	p = [None] * n
	q = [0]
	p[0] = -1
	i = 0
	while i < len(q):
		x = q[i]
		i += 1
		for v in g[x]:
			if p[v] is None:
				p[v] = x
				q.append(v)
	d = [None] * n
	dx = [None] * n
	for i in range(len(q) - 1, -1, -1):
		x = q[i]
		P = p[x]
		z = a[x]
		for v in g[x]:
			if v != P:
				z ^= dx[v]
		c = 0
		for v in g[x]:
			if v != P:
				if d[v]:
					c += 1
					if z == 0:
						print('YES')
						return
		if c > 1:
			print('YES')
			return
		dx[x] = z
		d[x] = z == X or c > 0
	print('NO')
for i in range(int(input())):
	solve()


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque, defaultdict
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000000 + 7
mod2 = 998244353
sys.setrecursionlimit(300000)
for _ in range(I()):
	(n, k) = M()
	a = L()
	adj = [[] for i in range(n)]
	for i in range(n - 1):
		(u, v) = M()
		adj[u - 1].append(v - 1)
		adj[v - 1].append(u - 1)
	axor = 0
	for i in a:
		axor ^= i
	if axor == 0:
		print('YES')
		continue
	if k == 2:
		print('NO')
		continue

	def bfs():
		q = deque()
		q.append(0)
		visited = [0] * n
		visited[0] = 1
		parent = [-1] * n
		bfstree = []
		while q:
			root = q.popleft()
			bfstree.append(root)
			for child in adj[root]:
				if not visited[child]:
					q.append(child)
					visited[child] = 1
					parent[child] = root
		return (bfstree, parent)
	cnt = 0
	(bfstree, parent) = bfs()
	while bfstree:
		cur = bfstree.pop()
		if a[cur] == axor:
			cnt += 1
		else:
			a[parent[cur]] ^= a[cur]
	if cnt >= 2:
		print('YES')
		continue
	print('NO')