You are given a tree consisting of n nodes numbered from 1 to n. The weights of edges of the tree can be any binary integer satisfying following Q conditions.

- 
		Each condition is of form u, v, x where u, v are nodes of the tree and x is a binary number. 

		For satisfying this condition,  sum of the weight of all the edges present in the path from node u to v of the tree, should have even if x = 0, odd otherwise. 
	

Now, you have to find out number of ways of assigning 0/1 (binary) weights to the edges of the tree satisfying the above conditions.
As the answer could be quite large, print your answer modulo 109 + 7.

-----Input-----
- The first line of input contains a single integer T denoting number of test cases.
- For each test case:
	
- First line contains two space separated integers n, Q.
- Each of the next n - 1 lines will contain two space separated integer  u, v denoting that there is an edge between vertex u and v in the tree.
- Each of the next Q lines will contain three space separated integer  u, v, x denoting a condition as stated in the probelm.

-----Output-----
- For each test case, output a single integer corresponding to the answer of the problem.

-----Constraints-----
- 1 ≤ u, v ≤ n
- 0 ≤ x ≤ 1

-----Subtasks-----
Subtask #1 : (10 points)
- Sum of each of variables n and Q over all the test cases ≤ 20

Subtask #2 : (20 points)
- Sum of each of variables n and Q over all the test cases ≤ 100

Subtask #3 : (30 points)
- Sum of each of variables n and Q over all the test cases ≤ 5000

Subtask #4 : (40 points)
- Sum of each of variables n and Q over all the test cases ≤ 100000

-----Example-----
Input:
3
3 2
1 2
1 3
1 2 0
1 3 0
3 0
1 2
2 3
3 1
1 2
2 3
1 2 1

Output:
1
4
2

-----Explanation-----
In the first example, 
You can only set the weight of each edge equal to 0 for satisfying the given condition. So, there is exactly one way of doing this. Hence answer is 1.

In the second example, 
There are two edges and there is no condition on the edges. So, you can assign them in 4 ways. 

In the third example, 
You have to assign the weight of edge between node 1 and 2 to 1. You can assign the remaining edge from 2 to 3 either 0 or 1. So, the answer is 2.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "import sys\n\ndef powc(x,n,m):\n  res = 1\n  xx=x\n  while n:\n    if n&1:\n      res = (res*xx)%m\n    xx=xx*xx%m\n    n >>= 1\n  return res\n\ndef findRoot():\n  S = [(0,-1)]\n  for u in S:\n    for w in V[u[0]]:\n      if w[0]!=u[1]:\n        S.append((w[0],u[0]))\n  S = [(S[-1][0],-1,0)]\n  D = [0]*n\n  for u in S:\n    for w in V[u[0]]:\n      if w[0]!=u[1]:\n        D[w[0]]=u[2]+1\n        S.append((w[0],u[0],u[2]+1))\n  d = S[-1][2]\n  size = d\n  u = S[-1][0]\n  while size/2<d:\n    for w in V[u]:\n      if D[w[0]]+1==D[u]:\n        u = w[0]\n        d -= 1\n        break \n  return u\n  \nclass Node:\n  def __init__(self, value, edge, parent = None):\n    self.value = value\n    self.edge = edge\n    if parent:\n      parent.addChild(self)\n    else:\n      self.parent = None\n    self.children = []\n  def addChild(self, node):\n    node.parent = self\n    self.children.append(node)\n  def __repr__(self):\n    r = repr(self.value)\n    for v in self.children:\n      r += ' ' + repr(v)\n    return r\n\n\ndef hangTree(root):\n  global NodesArray\n  NodesArray = [None]*n\n  S=[(root, Node(root,-1),-1)]\n  NodesArray[root] = S[0][1]\n  for u in S:\n    for v in V[u[0]]:\n      if v[0] != u[2]:\n        node = Node(v[0],v[1],u[1])\n        NodesArray[v[0]] = node\n        S.append((v[0],node,u[0]))\n\ndef findPath2(u,v):\n  n0 = NodesArray[u]\n  n1 = NodesArray[v]\n  q = [0]*n\n  while n0.parent:\n    q[n0.edge] ^= 1\n    n0 = n0.parent\n  while n1.parent:\n    q[n1.edge] ^= 1\n    n1 = n1.parent\n  return q\n         \nT = int(sys.stdin.readline())\nfor _ in range(T):\n  n,Q = list(map(int,sys.stdin.readline().split()))\n  V = list(map(list,[[]]*n))\n  W = [0]*n\n  for i in range(n-1):\n    u,v = list(map(int,sys.stdin.readline().split()))\n    u-=1\n    v-=1\n    V[u].append((v,i))\n    V[v].append((u,i))\n    W[u] += 1\n    W[v] += 1\n  easy = n==1\n  root = findRoot()\n  hangTree(root)\n  M = []\n  for _ in range(Q):\n    u,v,x = list(map(int,sys.stdin.readline().split()))\n    if not easy:\n      q = findPath2(u-1,v-1)\n      q[-1] = x\n      M.append(q)\n  if easy:\n    print(1)\n    continue\n  empty = [0]*n\n  bad = [0]*n\n  bad[-1] = 1\n  is_there_bad = False\n  empty_cnt = 0\n  i = 0\n  for q in M:\n    i += 1\n    if q == empty:\n      empty_cnt += 1\n      continue\n    if q == bad:\n      is_there_bad = True\n      break\n    o = q.index(1)\n    for next in range(i,Q):\n      if M[next][o]==1:\n        for k in range(n):\n          M[next][k] ^= q[k]\n  if is_there_bad:\n    print(0)\n  else:\n    print(powc(2,n-1-Q+empty_cnt,10**9+7))\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 18033