"Say my Name".
Todd Alquist is being taught the process of cooking methamphetamine, but to see whether he's really capable of learning it, Walt gives him a problem to solve. Since he can't solve it, he asks you for help.
You are given a tree with $N$ vertices (numbered $1$ through $N$), rooted at the vertex $1$. There is an integer written at each vertex; for each valid $i$, the value of vertex $i$ is $A$$i$.There also exists a special integer $K$. 
Choose any leaf node, denoted by $X$, and go down a simple path from $root$ to $X$.
Let $S$ denote the set of all nodes lying on the simple path from $root$ to $X$.
For all $ i $ $\epsilon $ $ S $, choose an integer $D$ $\epsilon$ $[2^{A[i]-1},2^{A[i]})$.

Informally, for every node $i$ lying on the simple path from $root$ to $X$, you have to choose an integer $D$ such that  $2^{A[i]-1}\leq D < 2^{A[i]}$.  
You now have to perform one of the two following operations :   
- Bitwise XOR of all chosen integers.  
- Bitwise AND of all chosen integers.   
You have to determine whether you can choose the values in such a way that after performing one of the given operations you can get an integer equal to $K$.  
- Note : A leaf is a node of the tree without any child nodes.
Determine if it is possible to obtain the value $K$ by performing the given operations.

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow. 
- First line of each testcase contains two space separated integers $N, K$ denoting the number of nodes and the value of the special integer .
- $N-1$ lines follow , each line contains two space separated integers $u,v$ denoting an edge between $u$ and $v$. 
- A single line follows containing $N$ space separated integers denoting the value of nodes.

-----Output:-----
For each testcase, output in a single line "YES"(without quotes) or "NO"(without quotes).

-----Constraints-----
- $1 \leq T \leq 10000$
- $2 \leq N \leq 5*10^5$
- $1 \leq K \leq 10^{18}$
- $1 \leq u,v \leq N$
- $ 1\leq A[i] \leq 64$
- Sum of $N$ over all test cases does not exceed 1e6.

-----Sample Input:-----
1
6 85
1 2
2 3
2 4
4 5
3 6
3 5 4 7 1 9

-----Sample Output:-----
YES

-----EXPLANATION:-----
There are two leaf nodes, 5 and 6
considering path from root to 5
we have nodes
1->2->4->5
we can select the values
5,26,75,1 and perform operation 1 that is XOR of all numbers to get 85

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
import sys,collections
input=sys.stdin.readline
def main():
 T=int(input())
 for _ in range(T):
  N,K=map(int,input().split())
  Tree={}
  for j in range(N):
   Tree[j]=[]
   
  for i in range(N-1):
   u,v=map(int,input().split())
   Tree[u-1].append(v-1)
   Tree[v-1].append(u-1)
   
  A=list(map(int,input().split()))
 
  vis=[0 for i in range(N)] #to mark visited vertices 0 for visited and             1 for not visited
  maxval=[[0,0] for i in range(N)] #Nx2 list where each i stores max             value till now and its count 
  minval=[0 for i in range(N)] #Nx2 list where each i stores min value             till now 
  lfnode=[] #list to store leaf nodes
  
  #Appending node 1
  vis[0]=1
  Q=collections.deque([0])
  maxval[0][0],maxval[0][1]=A[0],1
  minval[0]=A[0]
 
  
  while(len(Q)!=0):
   a=Q.pop()
   mv1=maxval[a][0]
   mv2=minval[a]
   
   flag=0 #to check leaf node
   
   for i in Tree[a]:
    if (vis[i]==0):
     vis[i]=1
     flag=1 #not a leaf node
     v=A[i]
     Q.append(i)
 
     #Comparing maximum value of parent node
     if (mv1<v):
      maxval[i][0],maxval[i][1]=v,1
      
     elif(mv1==v):
      maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1
 
     else:
      maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1]
 
      
     #Comparing minimum value of parent node
     if (mv2>v):
      minval[i]=v
     elif(v==mv2):
      minval[i]=mv2
     else:
      minval[i]=minval[a]
   
 
   if (flag==0):
    lfnode.append(a)
 
  
  flag=0 #For answer if 0 then NO else YES
 
  K1=len(bin(K))-2 #length of K
  
  #print(lfnode,val)
  for i in lfnode:
   v1,v2=maxval[i][0],maxval[i][1]
   
   if (v1>K1 and v2%2==0):
    flag=1
   elif(v1==K1 and v2%2==1):
    flag=1
 
 
   v11=minval[i]
   if (v11>K1 and v11!=v1):
    flag=1
   elif(v11==K1):
    flag=1
    
   
   if(flag==1):
    break
   
  if (flag==1):
   print("YES")
  else:
   print("NO")
main()

# cook your dish here
import sys,collections
input=sys.stdin.readline
def main():
 T=int(input())
 for _ in range(T):
  N,K=map(int,input().split())
  Tree={}
  for j in range(N):
   Tree[j]=[]
   
  for i in range(N-1):
   u,v=map(int,input().split())
   Tree[u-1].append(v-1)
   Tree[v-1].append(u-1)
   
  A=list(map(int,input().split()))
 
  vis=[0 for i in range(N)] #to mark visited vertices 0 for visited and             1 for not visited
  maxval=[[0,0] for i in range(N)] #Nx2 list where each i stores max             value till now and its count 
  minval=[0 for i in range(N)] #Nx2 list where each i stores min value             till now 
  lfnode=[] #list to store leaf nodes
  
  #Appending node 1
  vis[0]=1
  Q=collections.deque([0])
  maxval[0][0],maxval[0][1]=A[0],1
  minval[0]=A[0]
 
  
  while(len(Q)!=0):
   a=Q.pop()
   mv1=maxval[a][0]
   mv2=minval[a]
   
   flag=0 #to check leaf node
   
   for i in Tree[a]:
    if (vis[i]==0):
     vis[i]=1
     flag=1 #not a leaf node
     v=A[i]
     Q.append(i)
 
     #Comparing maximum value of parent node
     if (mv1<v):
      maxval[i][0],maxval[i][1]=v,1
      
     elif(mv1==v):
      maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1
 
     else:
      maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1]
 
      
     #Comparing minimum value of parent node
     if (mv2>v):
      minval[i]=v
     elif(v==mv2):
      minval[i]=mv2
     else:
      minval[i]=minval[a]
   
 
   if (flag==0):
    lfnode.append(a)
 
  
  flag=0 #For answer if 0 then NO else YES
 
  K1=len(bin(K))-2 #length of K
  
  #print(lfnode,val)
  for i in lfnode:
   v1,v2=maxval[i][0],maxval[i][1]
   
   if (v1>K1 and v2%2==0):
    flag=1
   elif(v1==K1 and v2%2==1):
    flag=1
 
 
   v11=minval[i]
   if (v11>K1 and v11!=v1):
    flag=1
   elif(v11==K1):
    flag=1
    
   
   if(flag==1):
    break
   
  if (flag==1):
   print("YES")
  else:
   print("NO")
main()

import sys,collections
input=sys.stdin.readline
def main():
 T=int(input())
 for _ in range(T):
  N,K=map(int,input().split())
  Tree={}
  for j in range(N):
   Tree[j]=[]
   
  for i in range(N-1):
   u,v=map(int,input().split())
   Tree[u-1].append(v-1)
   Tree[v-1].append(u-1)
   
  A=list(map(int,input().split()))
 
  vis=[0 for i in range(N)] #to mark visited vertices 0 for visited and             1 for not visited
  maxval=[[0,0] for i in range(N)] #Nx2 list where each i stores max             value till now and its count 
  minval=[0 for i in range(N)] #Nx2 list where each i stores min value             till now 
  lfnode=[] #list to store leaf nodes
  
  #Appending node 1
  vis[0]=1
  Q=collections.deque([0])
  maxval[0][0],maxval[0][1]=A[0],1
  minval[0]=A[0]
 
  
  while(len(Q)!=0):
   a=Q.pop()
   mv1=maxval[a][0]
   mv2=minval[a]
   
   flag=0 #to check leaf node
   
   for i in Tree[a]:
    if (vis[i]==0):
     vis[i]=1
     flag=1 #not a leaf node
     v=A[i]
     Q.append(i)
 
     #Comparing maximum value of parent node
     if (mv1<v):
      maxval[i][0],maxval[i][1]=v,1
      
     elif(mv1==v):
      maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1
 
     else:
      maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1]
 
      
     #Comparing minimum value of parent node
     if (mv2>v):
      minval[i]=v
     elif(v==mv2):
      minval[i]=mv2
     else:
      minval[i]=minval[a]
   
 
   if (flag==0):
    lfnode.append(a)
 
  
  flag=0 #For answer if 0 then NO else YES
 
  K1=len(bin(K))-2 #length of K
  
  #print(lfnode,val)
  for i in lfnode:
   v1,v2=maxval[i][0],maxval[i][1]
   
   if (v1>K1 and v2%2==0):
    flag=1
   elif(v1==K1 and v2%2==1):
    flag=1
 
 
   v11=minval[i]
   if (v11>K1 and v11!=v1):
    flag=1
   elif(v11==K1):
    flag=1
    
   
   if(flag==1):
    break
   
  if (flag==1):
   print("YES")
  else:
   print("NO")
main()

import sys,collections
input = sys.stdin.readline 

def solve():
 T = int(input())
 for _ in range(T):
  N,K = list(map(int,input().split()))
  
  Tree = {}
  for j in range(N):
   Tree[j] = []
   
  for i in range(N-1):
   u,v = list(map(int, input().split()))
   Tree[u-1].append(v-1)
   Tree[v-1].append(u-1)
   
  A = list(map(int, input().split()))
  
  vis = [0 for i in range(N)]
  maxval = [[0,0] for i in range(N)]
  minval = [0 for i in range(N)]
  lfnode = []
  
  vis[0]=1
  Q=collections.deque([0])
  maxval[0][0],maxval[0][1]=A[0],1
  minval[0]=A[0]
 
  
  while(len(Q)!=0):
   a=Q.pop()
   mv1=maxval[a][0]
   mv2=minval[a]
   
   flag=0 #to check leaf node
   
   for i in Tree[a]:
    if (vis[i]==0):
     vis[i]=1
     flag=1 
     v=A[i]
     Q.append(i)
 
     
     if (mv1<v):
      maxval[i][0],maxval[i][1]=v,1
      
     elif(mv1==v):
      maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1
 
     else:
      maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1]
 
      
     
     if (mv2>v):
      minval[i]=v
     elif(v==mv2):
      minval[i]=mv2
     else:
      minval[i]=minval[a]
   
 
   if (flag==0):
    lfnode.append(a)
 
  
  flag=0 
 
  K1=len(bin(K))-2 
  
  #print(lfnode,val)
  for i in lfnode:
   v1,v2=maxval[i][0],maxval[i][1]
   
   if (v1>K1 and v2%2==0):
    flag=1
   elif(v1==K1 and v2%2==1):
    flag=1
 
 
   v11=minval[i]
   if (v11>K1 and v11!=v1):
    flag=1
   elif(v11==K1):
    flag=1
    
   
   if(flag==1):
    break
   
  if (flag==1):
   print("YES")
  else:
   print("NO")
  
 
solve() 


import sys,collections
input = sys.stdin.readline 

def solve():
 T = int(input())
 for _ in range(T):
  N,K = list(map(int,input().split()))
  
  Tree = {}
  for j in range(N):
   Tree[j] = []
   
  for i in range(N-1):
   u,v = list(map(int, input().split()))
   Tree[u-1].append(v-1)
   Tree[v-1].append(u-1)
   
  A = list(map(int, input().split()))
  
  vis = [0 for i in range(N)]
  maxval = [[0,0] for i in range(N)]
  minval = [0 for i in range(N)]
  lfnode = []
  
  vis[0]=1
  Q=collections.deque([0])
  maxval[0][0],maxval[0][1]=A[0],1
  minval[0]=A[0]
 
  
  while(len(Q)!=0):
   a=Q.pop()
   mv1=maxval[a][0]
   mv2=minval[a]
   
   flag=0 #to check leaf node
   
   for i in Tree[a]:
    if (vis[i]==0):
     vis[i]=1
     flag=1 
     v=A[i]
     Q.append(i)
 
     
     if (mv1<v):
      maxval[i][0],maxval[i][1]=v,1
      
     elif(mv1==v):
      maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1
 
     else:
      maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1]
 
      
     
     if (mv2>v):
      minval[i]=v
     elif(v==mv2):
      minval[i]=mv2
     else:
      minval[i]=minval[a]
   
 
   if (flag==0):
    lfnode.append(a)
 
  
  flag=0 
 
  K1=len(bin(K))-2 
  
  #print(lfnode,val)
  for i in lfnode:
   v1,v2=maxval[i][0],maxval[i][1]
   
   if (v1>K1 and v2%2==0):
    flag=1
   elif(v1==K1 and v2%2==1):
    flag=1
 
 
   v11=minval[i]
   if (v11>K1 and v11!=v1):
    flag=1
   elif(v11==K1):
    flag=1
    
   
   if(flag==1):
    break
   
  if (flag==1):
   print("YES")
  else:
   print("NO")
  
 
solve() 


import sys,collections
input=sys.stdin.readline
def main1():
 T=int(input())
 for _ in range(T):
  N,K=map(int,input().split())
  Tree={} 
  for j in range(N):
   Tree[j]=[]
   
  for i in range(N-1):
   u,v=map(int,input().split())
   Tree[u-1].append(v-1)
   Tree[v-1].append(u-1)
   
  A=list(map(int,input().split()))
 
  vis=[0 for i in range(N)] 
  maxval=[[0,0] for i in range(N)] 
  minval=[0 for i in range(N)] 
  lfnode=[] 
  
  #Appending node 1
  vis[0]=1
  Q=collections.deque([0])
  maxval[0][0],maxval[0][1]=A[0],1
  minval[0]=A[0]
 
  
  while(len(Q)!=0):
   a=Q.pop()
   mv1=maxval[a][0]
   mv2=minval[a]
   
   flag=0 #to check leaf node
   
   for i in Tree[a]:
    if (vis[i]==0):
     vis[i]=1
     flag=1 
     v=A[i]
     Q.append(i)
 
     
     if (mv1<v):
      maxval[i][0],maxval[i][1]=v,1
      
     elif(mv1==v):
      maxval[i][0],maxval[i][1]=mv1,maxval[a][1]+1
 
     else:
      maxval[i][0],maxval[i][1]=maxval[a][0],maxval[a][1]
 
      
     
     if (mv2>v):
      minval[i]=v
     elif(v==mv2):
      minval[i]=mv2
     else:
      minval[i]=minval[a]
   
 
   if (flag==0):
    lfnode.append(a)
 
  
  flag=0 
 
  K1=len(bin(K))-2 
  
  #print(lfnode,val)
  for i in lfnode:
   v1,v2=maxval[i][0],maxval[i][1]
   
   if (v1>K1 and v2%2==0):
    flag=1
   elif(v1==K1 and v2%2==1):
    flag=1
 
 
   v11=minval[i]
   if (v11>K1 and v11!=v1):
    flag=1
   elif(v11==K1):
    flag=1
    
   
   if(flag==1):
    break
   
  if (flag==1):
   print("YES")
  else:
   print("NO")
  
 
main1()