import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N = int(input()) edge = [[] for v in range(N)] for _ in range(N-1): a,b,c = mi() edge[a-1].append((b-1,c)) edge[b-1].append((a-1,c)) parent = [(-1,-1) for v in range(N)] topo = [] deq = deque([0]) while deq: v = deq.popleft() topo.append(v) for nv,c in edge[v]: if nv==parent[v][0]: continue parent[nv] = (v,c) deq.append(nv) dp = [[(0,1) for k in range(30)] for v in range(N)] for v in topo[::-1]: for nv,c in edge[v]: if nv==parent[v][0]: continue for k in range(30): x,y = dp[v][k] z,w = dp[nv][k] if c>>k & 1: dp[v][k] = (x+z+y*w,y+w) else: dp[v][k] = (x+z,y) res = 0 for k in range(30): res += dp[0][k][0] * pow(2,k,10**9+7) print(res % (10**9 + 7))