# ローカルだと 3500 ms くらい (パスグラフを除けば 500 ms くらい) import sys input = sys.stdin.readline sys.setrecursionlimit(10**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())) B = 30 ans = 0 MOD = 10**9 + 7 def dfs(u, p): dp = [[0] * 2 for _ in range(B)] for b in range(B): dp[b][(A[u] >> b) & 1] = 1 for v in G[u]: if v == p: continue dp_new = [[0] * 2 for _ in range(B)] dp_v = dfs(v, u) for b in range(B): # 切る dp_new[b][0] += dp[b][0] * dp_v[b][1] dp_new[b][1] += dp[b][1] * dp_v[b][1] # 切らない(繋ぐ) dp_new[b][0] += dp[b][0] * dp_v[b][0] dp_new[b][1] += dp[b][0] * dp_v[b][1] dp_new[b][1] += dp[b][1] * dp_v[b][0] dp_new[b][0] += dp[b][1] * dp_v[b][1] dp_new[b][0] %= MOD dp_new[b][1] %= MOD dp = dp_new return dp dp = dfs(0, -1) for b in range(B): ans += (1 << b) * dp[b][1] ans %= MOD print(ans) if __name__ == "__main__": main()