#include "bits/stdc++.h"
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
using namespace std;
using ll = long long;

const int mod = 1e9+7;
ll ans = 0;

void dfs(auto &g, int u, int par, auto &pref, auto &sz)
{
    sz[u] = 1;
    for (auto [v, w] : g[u]) {
        if (v == par) continue;
        pref[v] = pref[u] ^ w;
        dfs(g, v, u, pref, sz);
        sz[u] += sz[v];
    }
}

array<int, 61> dfs2(auto &g, int u, int par, auto &pref, auto &sz)
{
    array<int, 61> ret{};
    int tot = 0;
    for (auto [v, w] : g[u]) {
        if (v == par) continue;
        auto child = dfs2(g, v, u, pref, sz);
        for (int i = 0; i < 61; ++i) {
            ll mul = 1LL << i; mul %= mod;
            ll ct = 1LL*child[i]*(tot-ret[i]) + 1LL*(sz[v]-child[i])*ret[i];
            ct %= mod;
            ans += mul*ct; ans %= mod;
            ret[i] += child[i];
        }
        tot += sz[v];
    }
    for (int i = 0; i < 61; ++i) {
        ll mul = 1LL << i; mul %= mod;
        ll ct = 0;
        if ((pref[u]>>i)&1) {
            ct = sz[u]-1-ret[i];
            ++ret[i];
        }
        else {
            ct = ret[i];
        }
        ct %= mod;
        ans += mul*ct; ans %= mod;
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

    int n; cin >> n;
    vector<vector<array<ll, 2>>> g(n);
    for (int i = 0; i < n-1; ++i) {
        int u, v; cin >> u >> v;
        ll w; cin >> w;
        g[--u].push_back({--v, w});
        g[v].push_back({u, w});
    }
    vector<ll> pref(n);
    vector<int> sz(n);
    dfs(g, 0, 0, pref, sz);
    dfs2(g, 0, 0, pref, sz);
    cout << ans;
}
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int ll
#define vi vector<int>
#define vb vector<bool>
#define vvb vector<vb >
#define pii pair<int,int>
#define ss second
#define ff first
#define vpii vector<pii>
#define vvi vector<vi >
#define vs vector<string>
#define vvs vector<vs >
#define pqi priority_queue <int>
#define minpqi priority_queue <int, vector<int>, greater<int> >
#define all(x) x.begin(),x.end()
#define mii map<int,int>
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define inp(arr,n) ll arr[n];rep(i,n){ cin>>arr[i];}
#define inp1(arr,n) ll arr[n+1];rep1(i,n){ cin>>arr[i];}
#define inp2d(arr,n,m) ll arr[n][m];rep(i,n)rep(j,m)cin>>arr[i][j];
#define inpg(adj,m) rep(i,m){int a,b;cin>>a>>b;adj[a].pb(b);adj[b].pb(a);}
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
#define print1(a,n) for(ll i=1;i<=n;i++){ cout<<a[i]<<endl;}
#define mod 1000000007
#define maxx 1000000000000000000
#define PI 3.141592653589793238462643383279
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define init(arr,a) memset(arr,a,sizeof(arr))
#define lb lower_bound
#define ub upper_bound
//          " "
vector<pii> v[200001];

long long sum=0;
long long value[200001];
void dfs(int node,int par,int xorr)
{
//	int sum=0;
//	int xorr=0;
	for(auto it:v[node])
	{
		if(it.first!=par)
		{
			xorr^=it.second;
			value[it.first]=xorr;
			dfs(it.first,node,xorr);
			xorr^=it.second;
			//return ans;
		}
	}
	return ;
}
signed main()
{

     int n;
     cin>>n;
    
     for1(i,n-1)
     {
     	int a,b,c;
     	cin>>a>>b>>c;
     	v[a].pb({b,c});
     	v[b].pb({a,c});
	 }
	 
	 dfs(1,0,0);
	 
	int ans=0;
	map<int,int>mpp;
	for(int i=2;i<=n;i++)
	{
		
		for(int j=0;j<=63;j++)
		{
			
			if((1ll<<j)&value[i])
			{
				mpp[j]++;
			}
		}
	}
	
	for0(i,64)
	{
		ans=ans%mod+((1ll<<i)%mod*((mpp[i]*(n-mpp[i]))%mod)%mod)%mod;
	}
	 //for1(i,n)cout<<visit[i]<<endl;
	 cout<<ans<<endl;
	 return 0;
     
     
     
		
	
}






