import sys sys.setrecursionlimit(10 ** 9) import pypyjit pypyjit.set_param('max_unroll_recursion=-1') MOD = 10 ** 9 + 7 n = int(input()) edges = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = map(int, input().split()) a -= 1 b -= 1 edges[a].append((b, c)) edges[b].append((a, c)) dp = [[1] * 30 for _ in range(n)] ans = 0 bi = [1 << i for i in range(30)] def dfs(pos, bpos): global ans for npos, c in edges[pos]: if npos == bpos: continue else: pass dfs(npos, pos) for i in range(30): if c >> i & 1: ans += dp[pos][i] * dp[npos][i] * bi[i] ans %= MOD dp[pos][i] += dp[npos][i] else: pass dfs(0, -1) print(ans)