#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll cnt[2][200009];
ll vec[200009];
ll val[200009];
ll par[200009],lev[200009];
vector<pair<ll,ll> >tmp;
ll pp[70];
vector<pair<ll,ll>>ad[200009];
ll n;
ll M;
void dfs(ll a,ll p, ll t)
{
    val[a]+=t;
    ll b,i,l=ad[a].size();
    for(i=0; i<l; i++)
    {
        b=ad[a][i].first;
        if(b!=p)
        {
            dfs(b,a,val[a]);
        }
    }
}
void dfs2(ll a,ll p,ll c)
{
    par[a]=p;
    lev[a]=lev[p]+1;
    vec[a]=c;
    ll b,i,l=ad[a].size(),d;
    for(i=0; i<l; i++)
    {
        b=ad[a][i].first;
        d=ad[a][i].second;
        if(b!=p)
        {
            dfs2(b,a,d);
        }
    }
}
ll call()
{
    ll a,b,c,x,y,ans=0,m,i,j,l,o,z;
    for(i=0; i<n; i++)
    {
        a=tmp[i].second;
        o=z=0;
        c=val[a]%2;
        c=(c+1)%2;
        ans+=cnt[c][a];
        l=ad[a].size();
        for(j=0; j<l; j++)
        {
            b=ad[a][j].first;
            if(b!=par[a])
            {
                x=cnt[0][a]-cnt[0][b]-z;
                y=cnt[1][b];
                ans+=(x*y);

                x=cnt[1][a]-cnt[1][b]-o;
                y=cnt[0][b];
                ans+=(x*y);
                o+=cnt[1][b];
                z+=cnt[0][b];

            }
        }
        c=val[a]%2;
        cnt[c][a]++;
        b=par[a];
        cnt[0][b]+=cnt[0][a];
        cnt[1][b]+=cnt[1][a];
    }

    return ans;
}
int main()
{
    ll a,b,c,d,e,i,j,k,l,m,x,y,t,p;
    M=(1e9)+7;
    pp[0]=1;
    for(i=1; i<=61; i++)
    {
        pp[i]=pp[i-1]*2;
    }
    scanf("%lld",&n);
    for(i=1; i<n; i++)
    {
        scanf("%lld%lld%lld",&a,&b,&c);
        ad[a].push_back({b,c});
        ad[b].push_back({a,c});
    }
    dfs2(1,0,0);
    for(i=1; i<=n; i++)
    {
        tmp.push_back({lev[i],i});
    }
    sort(tmp.rbegin(),tmp.rend());

    ll ans=0;
    for(i=0; i<60; i++)
    {
        for(j=1; j<=n; j++)
        {
            if((vec[j]&pp[i])!=0)
            {
                val[j]=1;
            }
            else
            {
                val[j]=0;
            }
            cnt[0][j]=cnt[1][j]=0;
        }
        dfs(1,0,0);
        x=call();
        //cout<<x<<endl;
        y=((x%M)*(pp[i]%M))%M;
        ans=(ans+y)%M;
    }
    printf("%lld\n",ans);
}

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    if(a == 0) return 0;
    b %= (M - 1);  //M must be prime here
    
    int res = 1;
    
    while(b > 0)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

const int N = 2e5 + 10;
vector<pii> g[N];

int arr[N];

void dfs(int node,int par = -1,int val = 0)
{
    if(par != -1)
    {
        arr[node] = val;
    }
    
    for(auto x : g[node])
    {
        if(x.F == par) continue;
        
        dfs(x.F,node,val^x.S);
            
    }
}

void solve()
{
   int n;
    cin >> n;
    
   int u,v,w;
    
    f(i,n-1)
    {
        cin >> u >> v >> w;
        g[u].pb({v,w});
        g[v].pb({u,w});
    }
    
    dfs(1);
    
    vector<int> vs;
    
    for(int i=1;i<=n;i++) vs.pb(arr[i]);
    
    int res = 0;
   
    f(j,60)
    {
        int c0 = 0;
        int c1 = 0;
        
        for(int i=0;i<n;i++)
          if((vs[i] >> j) & 1) c1++;
          else c0++;
            
        int ways = (c0*c1);
        ways %= MOD;
        
        int pw = mod_pow(2,j);
        ways*=pw;
        ways%= MOD;
        res+=ways;
        res%=MOD;
            
    }
    
    res %= MOD;
    cout <<res;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}
