MOD = 998244353 n = gets.to_i g = Array.new(n) { [] } (n - 1).times do a, b = gets.split.map(&:to_i) g[a - 1] << b - 1 g[b - 1] << a - 1 end seen = Array.new(n, false) seen[0] = true postorder = [] child = Array.new(n) { [] } stk = [~0, 0] while !stk.empty? u = stk.pop if u >= 0 g[u].each do |v| next if seen[v] seen[v] = true child[u] << v stk.push(~v, v) end else postorder << ~u end end a = gets.split.map(&:to_i) ans = 0 30.times do |k| dp0 = Array.new(n, 0) dp1 = Array.new(n, 0) postorder.each do |u| if (a[u] >> k & 1) == 1 dp1[u] = 1 else dp0[u] = 1 end child[u].each do |v| ndp0 = dp0[u]*dp0[v] + dp1[u]*dp1[v] + dp0[u]*dp1[v] ndp1 = dp0[u]*dp1[v] + dp1[u]*dp0[v] + dp1[u]*dp1[v] dp0[u] = ndp0 % MOD dp1[u] = ndp1 % MOD end end ans += dp1[0] << k end ans %= MOD puts ans