//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#include <bits/stdc++.h>
using namespace std;
 
typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
#define pb push_back
#define MAXN 500005
const ll N=60;
#define INF (ll)1e18
#define mod 1000000007
//#define mod 998244353
#define fi first
#define se second
#define mkp make_pair
#define sze(x) ((ll)x.size())
#define all(v) v.begin(),v.end()
#define endl '\n'
#define level 20
ll timer,cc,cc1;


void boost()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll dp[MAXN],b[N];
vl V[MAXN];
map<pll,ll> mp;

void dfs(ll cur,ll prev)
{
    ll j;
    j=mp[mkp(cur,prev)];
    dp[cur]=dp[prev]^j;
    
    for(auto x : V[cur])
    {
        if(x!=prev)
        {
            dfs(x,cur);
        }
    }
}


int main()
{
    boost();
    
    ll i,t,n,q,l,r,ans,mid,c=0,j,k,z,tc;
    ll h,m,u,mm,w,mx,x,y,l1,r1,d=0,mask;
    ld f,f1;
    
    cin>>n;
    
    for(i=0;i<(n-1);i++)
    {
        cin>>x>>y>>z;
        V[x].pb(y);
        V[y].pb(x);
        mp[mkp(x,y)]=z;
        mp[mkp(y,x)]=z;
    }
    
    dfs(1,0);
    ans=0;
    
    for(i=0;i<60;i++)
    {
        c=0;
        d=0;
        for(j=1;j<=n;j++)
        {
            if((1LL<<i)&dp[j])
            {
                c++;
            }
            
            else
            d++;
        }
        
        z=c*d;
        l=(1LL<<i);
        l%=mod;
        z=z%mod;
        z=z*l;
        z%=mod;
        
        ans+=z;
        ans%=mod;
    }
    
    cout<<ans<<endl;
    
    
return 0;
}
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define INF (int)2e9
#define mod 1000000007
#define PI 3.141592653589793238
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define repz(i,b) for(int i=0; i<b; ++i)
#define repdz(i,b) for(int i=b; i>=0; --i)
#define trav(i,a) for(auto &i: a)
#define pb push_back
#define pf push_front
#define nl '\n'
#define sp ' '
#define sz(a) a.size()
#define read(p) repz(i,sz(p)) cin>>p[i]

typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>>  vvl;
typedef pair<int, int> pii;
typedef vector<vector<pair<ll ,ll>>> vvp;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pll;

int n;
vvp adj;

ll paths;

pll dfs(ll v, ll prev, int b){
	vpl paritypaths;
	ll tx=0, ty=0;
	trav(p, adj[v]){
		if(p.first==prev) continue;
		pii np=dfs(p.first, v, b);
		if(p.second&((ll)1<<b)) swap(np.first, np.second);
		tx+=np.first; ty+=np.second;
		tx%=mod; ty%=mod;
		if(p.second&((ll)1<<b)) {
			ty++; np.second++;
		}else {
			tx++; np.first++;
		}
		paritypaths.pb({np.first, np.second});
	}


	paths+=ty;
	paths%=mod;

	trav(p,paritypaths){
		paths+=p.first*(ty-p.second);
		paths%=mod;
	}

	return {tx,ty};
}

ll ppow(ll n, ll m){
	if(m==0) return 1;
	ll tmp=ppow(n,m/2);
	tmp = tmp * tmp % mod;
	return m%2 ? tmp*n % mod : tmp;
}

void solve(){

	cin>>n;
	adj.assign(n, vpl());

	repz(i, n-1){
		ll u, v, w; cin>>u>>v>>w; u--; v--;
		adj[u].pb({v,w}); adj[v].pb({u,w});
	}

	ll ans=0;
	repz(b,60){
		paths=0;
		dfs(0,0,b);
		ans+=paths*ppow(2,b);
		ans%=mod;
		// cout<<paths<<sp<<ans<<nl;
	}

	cout<<ans;


}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(10);
	int ts=1;
	//cin>>ts;
	while(ts--){
		solve();
	}
	return 0;
	
}
