import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, M, X = map(int, readline().split()) A = list(map(int, readline().split())) + [0] A = [0] + [x ^ y for x, y in zip(A, A[1:])] m = map(int, read().split()) graph = [[] for _ in range(N + 1)] for t, x, y in zip(m, m, m): x -= 1 graph[x].append((y, t)) graph[y].append((x, t)) C = [0] * (N + 1) root = [-1] * (N + 1) is_ng = False for v in range(N + 1): if root[v] != -1: continue stack = [v] root[v] = v while stack: v = stack.pop() for w, x in graph[v]: if root[w] == -1: root[w] = root[v] C[w] = C[v] ^ x stack.append(w) continue if C[w] != C[v] ^ x: is_ng = True if is_ng: print(0) exit() for v in range(N + 1): X ^= C[v] * A[v] if v != root[v]: A[root[v]] ^= A[v] def row_transform_over_F2(A, highest=60): for k in range(highest, -1, -1): I = np.where((A >> k) == 1)[0] if len(I) == 0: continue i = I[0] x = A[i] A ^= ((A >> k) & 1) * x A[i] = x nums = np.array([A[v] for v in range(N + 1) if v == root[v] != 0], np.int32) row_transform_over_F2(nums, 31) nums.sort() nums = nums[::-1] for x in nums: if x <= X: X ^= x if X != 0: print(0) else: MOD = 10 ** 9 + 7 free = int(np.sum(nums == 0)) print(pow(2, free, MOD))