← Home
package main

import (
	"bufio"
	"io"
	"os"
)

func main() {
	data, _ := io.ReadAll(os.Stdin)
	pos := 0
	nextInt := func() int {
		for pos < len(data) && data[pos] <= ' ' {
			pos++
		}
		if pos >= len(data) {
			return 0
		}
		res := 0
		for pos < len(data) && data[pos] > ' ' {
			res = res*10 + int(data[pos]-'0')
			pos++
		}
		return res
	}

	t := nextInt()
	if t == 0 {
		return
	}
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	for i := 0; i < t; i++ {
		n := nextInt()
		q := nextInt()

		initialColors := make([]int, n+1)
		for j := 1; j <= n; j++ {
			initialColors[j] = nextInt()
		}

		adj := make([][]int, n+1)
		for j := 0; j < n-1; j++ {
			u := nextInt()
			v := nextInt()
			adj[u] = append(adj[u], v)
			adj[v] = append(adj[v], u)
		}

		parent := make([]int, n+1)
		queue := make([]int, 0, n)
		queue = append(queue, 1)
		visited := make([]bool, n+1)
		visited[1] = true
		for len(queue) > 0 {
			curr := queue[0]
			queue = queue[1:]
			for _, nxt := range adj[curr] {
				if !visited[nxt] {
					visited[nxt] = true
					parent[nxt] = curr
					queue = append(queue, nxt)
				}
			}
		}

		color := make([]int, n+1)
		bc := make([]int, n+1)
		cnt2 := make([]int, n+1)
		cnt3 := make([]int, n+1)
		B, E_B, C_3 := 0, 0, 0
		root := 1

		S := func(x int) int {
			if color[x] == 1 {
				return cnt2[x]
			}
			return cnt3[x]
		}

		contrib := func(x int) int {
			res := S(x)
			if x == root {
				if color[root] == 1 && bc[root] >= 3 {
					res += 1
				}
			}
			return res
		}

		toggle := func(u int) {
			p := parent[u]
			pp := 0
			if p != 0 {
				pp = parent[p]
			}

			C_3 -= contrib(u)
			if p != 0 {
				C_3 -= contrib(p)
			}
			if pp != 0 {
				C_3 -= contrib(pp)
			}

			old_color_u := color[u]
			color[u] ^= 1
			d_color := color[u] - old_color_u

			B += d_color

			if p != 0 {
				if color[p] == 1 {
					E_B += d_color
				}
			}
			E_B += d_color * bc[u]

			if p != 0 {
				if bc[u] >= 2 {
					cnt2[p] += d_color
				}
				if bc[u] >= 3 {
					cnt3[p] += d_color
				}

				old_bc_p := bc[p]
				bc[p] += d_color

				if pp != 0 && color[p] == 1 {
					if old_bc_p < 2 && bc[p] >= 2 {
						cnt2[pp] += 1
					}
					if old_bc_p >= 2 && bc[p] < 2 {
						cnt2[pp] -= 1
					}
					if old_bc_p < 3 && bc[p] >= 3 {
						cnt3[pp] += 1
					}
					if old_bc_p >= 3 && bc[p] < 3 {
						cnt3[pp] -= 1
					}
				}
			}

			C_3 += contrib(u)
			if p != 0 {
				C_3 += contrib(p)
			}
			if pp != 0 {
				C_3 += contrib(pp)
			}
		}

		for j := 1; j <= n; j++ {
			if initialColors[j] == 1 {
				toggle(j)
			}
		}

		for j := 0; j < q; j++ {
			u := nextInt()
			toggle(u)
			if B > 0 && E_B == B-1 && C_3 == 0 {
				out.WriteString("Yes\n")
			} else {
				out.WriteString("No\n")
			}
		}
	}
}