#include<bits/stdc++.h>
using namespace std; 
typedef unsigned long long ull; 
const ull maxn=800005; 
ull w[maxn]; 
const ull mod=1e9+7; 
ull head[maxn], to[maxn], nex[maxn], val[maxn], cnt, dep[maxn]; 
void add(ull i, ull j, ull w){
    cnt++; 
    to[cnt]=j; val[cnt]=w; 
    nex[cnt]=head[i]; head[i]=cnt; 
}
void dfs(ull x){
    for(ull i=head[x]; i; i=nex[i]){
        ull y=to[i]; 
        if(dep[y]) 
            continue; 
        dep[y]=dep[x]+1; 
        w[y]=w[x]^val[i]; 
        dfs(y); 
    }
}
signed main(){
    ull n; 
    scanf("%llu", &n); 
    for(ull i=2; i<=n; i++){
        ull u, v, w; 
        scanf("%llu%llu%llu", &u, &v, &w); 
        add(v, u, w); add(u, v, w); 
    }
    dfs(dep[1]=1); 
    ull ans=0; 
    for(ull i=0; i<=60; i++){
        ull cnt=0; 
        for(ull j=1; j<=n; j++)
            if(w[j]>>i&1) cnt++;
        ans=(ans+(1LL<<i)%mod*cnt%mod*(n-cnt)%mod)%mod; 
    }
    ans=(ans%mod+mod)%mod; 
    printf("%llu", ans); 
    return 0; 
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<Pr>>;

ll mod = 1000000007;

int main() {
    //GraphInput
    ll N; cin >> N;
    Graph G(N+1);
    rep(i,N-1){
        ll a,b,c; cin >> a >> b >> c;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    ll ans = 0;
    rep(i,60){
        //Graph G(N+1);
        ll base = (1LL<<i);
        /*for(auto p:path){
            ll a = get<0>(p), b = get<1>(p), c = get<2>(p);
            if(c&base){
                G[a].push_back(make_pair(b,1));
                G[b].push_back(make_pair(a,1));
            }
            else{
                G[a].push_back(make_pair(b,0));
                G[b].push_back(make_pair(a,0));
            }
        }*/
        ll odd = 0,ev = 1;
        //BFS (普通の幅優先探索)
        queue<int> go; ll dist[N+1]; // ll par[N+1];
        rep(i,N+1){
            dist[i] = 2000000000;
        }
        dist[1] = 0; go.push(1);
        while(!go.empty()){
            int s = go.front(); go.pop();
            for(auto q:G[s]){
                ll x = q.first; ll b = q.second;
                ll a = 0;
                if(b&base) a = 1;
                if(dist[x]<=dist[s]+a) continue;
                dist[x] = dist[s] + a;
                if(dist[x]%2==0) ev++;
                else odd++;
                //par[x] = s;
                go.push(x);
            }
        }
        ans += base%mod*(odd*ev%mod)%mod;
        ans %= mod;
    }
    cout << ans << endl;
}