import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) MOD = 10**9 + 7 def main(): N = int(input()) G = [[] for _ in range(N)] for _ in range(N - 1): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].append(v) G[v].append(u) A = list(map(int, input().split())) # 非再帰の実装 # Ref: https://qiita.com/Kiri8128/items/2b0023bed9af642c751c ans = 0 parent = [-1] * N dp = [[0] * 2 for _ in range(N)] for b in range(30): stack = [~0, 0] # スタック while stack: u = stack.pop() if u >= 0: # 行きがけの処理 for v in G[u]: if parent[u] == v: continue if parent[v] == -1: parent[v] = u stack.append(~v) # 帰りがけ用 stack.append(v) # 行きがけ用 else: # 帰りがけの処理 u = ~u dp[u][0] = dp[u][1] = 0 dp[u][(A[u] >> b) & 1] = 1 for v in G[u]: if parent[u] == v: continue dp_new = [0] * 2 dp_u = dp[u] dp_v = dp[v] # 辺 (u, v) を削除する dp_new[0] += dp_u[0] * dp_v[1] dp_new[1] += dp_u[1] * dp_v[1] # 辺 (u, v) を削除しない(繋ぐ) dp_new[0] += dp_u[0] * dp_v[0] dp_new[1] += dp_u[0] * dp_v[1] dp_new[1] += dp_u[1] * dp_v[0] dp_new[0] += dp_u[1] * dp_v[1] dp_new[0] %= MOD dp_new[1] %= MOD dp[u] = dp_new ans += (1 << b) * dp[0][1] ans %= MOD print(ans) if __name__ == "__main__": main()