#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5;
const int inf=1e9;
vector<pair<int,long>> g[siz];
long dist[siz];
void dfs(int v, int par, long d){
	dist[v] = d;
	for(pair<int,long> p:g[v]){
		int u = p.first;
		long w = p.second;
		if(u == par) continue;
		dfs(u, v, d ^ w);
	}
}
long calc(long x, int j){
  	rep(i,0,j) (x *= 2) %= mod;
  	return x;
}
int main(){
	int N; cin>>N;
	int a,b; long c;
	rep(i,0,N-1){
		cin>>a>>b>>c; a--; b--;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	dfs(0, -1, 0);
	long cnt[60] = {};
	rep(i,0,N)rep(j,0,60){
		if(dist[i] & (1L<<j)) cnt[j]++;
	}
	long ans = 0;
	rep(j,0,60) (ans += calc(cnt[j] * (N-cnt[j]) % mod, j)) %= mod;
	cout<<ans<<endl;
}
#include <bits/stdc++.h>
using namespace std;

using lli = long long int;
using ii = pair<int, lli>;

const int MAXN = 2e5;
const lli MOD = 1e9+7;

int n;
vector<ii> adj[MAXN+1];

lli rootXor[MAXN+1];
void dfs(int u, int p, lli x) {
    rootXor[u] = x;

    for(ii v: adj[u]) {
        if(v.first == p) {
            continue;
        }

        dfs(v.first, u, x ^ v.second);
    }
}

lli safeMult(lli a, lli b) {
    if(!b) {
        return 0;
    }

    if(b%2) {
        return (safeMult(a, b-1) + a) % MOD;
    }
    else {
        lli aux = safeMult(a, b/2);
        return (aux + aux) % MOD;
    }
}

int main() {
    scanf("%d", &n);

    for(int i=0; i<n-1; i++) {
        int u, v;
        lli w;
        scanf("%d %d %lld", &u, &v, &w);

        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    dfs(1, 1, 0);

    vector<lli> ones(60, 0);

    lli ans = 0;
    for(int i=1; i<=n; i++) {
        lli cand = 0;
        for(int j=0; j<60; j++) {
            lli zeroes = (i-1)-ones[j];
            if(rootXor[i]&(lli(1) << j)) {
                cand += safeMult(lli(1) << j, zeroes);
            }
            else {
                cand += safeMult(lli(1) << j, ones[j]);
            }
            cand = cand % MOD;
        }
        ans = (ans + cand) % MOD;

        for(int j=0; j<60; j++) {
            if(rootXor[i]&(lli(1) << j)) {
                ones[j]++;
            }
        }
    }
    printf("%lld\n", ans);
}
