class UnionFind: def __init__(self, n): self.n = n self.par = [-1] * n self.group_ = n def find(self, x): if self.par[x] < 0: return x lst = [] while self.par[x] >= 0: lst.append(x) x = self.par[x] for y in lst: self.par[y] = x return x def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x self.group_ -= 1 return True def size(self, x): return -self.par[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) @property def group(self): return self.group_ n, m, x = map(int, input().split()) A = list(map(int, input().split())) T = [0] * m L = [0] * m R = [0] * m n += 1 UF = UnionFind(2 * n) for i in range(m): T[i], L[i], R[i] = map(int, input().split()) L[i] -= 1 if T[i] == 0: UF.unite(L[i], R[i]) UF.unite(L[i] + n, R[i] + n) else: UF.unite(L[i], R[i] + n) UF.unite(L[i] + n, R[i]) for i in range(n): if UF.same(i, i + n): print(0) exit() pari = [False] * n for i in range(n): pari[i] = UF.find(i) < n for i in range(n - 1): if pari[i] != pari[i + 1]: x ^= A[i] for i in range(n): UF.unite(i, i + n) X = {} for i in range(n): if UF.same(i, 0): continue r = UF.find(i) if i != 0: X[r] = X.get(r, 0) ^ A[i - 1] if i != n - 1: X[r] = X.get(r, 0) ^ A[i] bases = [] z = 0 for v in X.values(): for b in bases: v = min(v, v ^ b) if v == 0: z += 1 else: bases.append(v) for b in bases: x = min(x, x ^ b) if x == 0: print(pow(2, z, 10**9 + 7)) else: print(0)