#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
void dfs(ll i, ll p, vector<vector<pair<ll,ll>>>& adj,vector<ll>& xors)
{

    for(auto t : adj[i])
    {
        if(t.first!=p)
        {
            xors[t.first] = xors[i]^t.second;
            dfs(t.first,i,adj,xors);
        }
    }

}

int main()
{
    ll t = 1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<vector<pair<ll,ll>>> adj(n);
        for(ll i = 0; i<n-1; i++)
        {
            ll x, y, w;
            cin>>x>>y>>w;
            x--; y--;
            adj[x].push_back({y,w});
            adj[y].push_back({x,w});
        }
        vector<ll> xors(n,0);
        dfs(0,-1,adj,xors);
        ll ans = 0;
        for(ll i = 0; i<=60; i++)
        {
            ll cnt = 0;
            for(ll j = 0; j<n;j++)
            {
                if((xors[j])&(1ll<<i)) cnt++;
            }
            ans = (ans + ((cnt*(n-cnt))%mod)*((1ll<<i)%mod))%mod;
        }
        cout<<ans<<endl;
    }
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

struct edge{
    int to;
    ll cost;
};

veci seen;
vecl dp;

void dfs(int i,ll rec,vector<vector<edge>> &G) {
    seen[i] = 1;
    dp[i] = rec;
    for(auto e : G[i]) {
        int ni = e.to;
        if(seen[ni]) continue;
        ll d = e.cost;
        dfs(ni,rec^d,G);
    }
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int N; cin >> N;
    vector<vector<edge>> G(N);
    REP(i,N-1) {
        int a,b; cin >> a >> b;
        a--,b--;
        ll w; cin >> w;
        G[a].push_back({b,w});
        G[b].push_back({a,w});
    }

    ll ans = 0;

    seen = veci(N);
    dp = vecl(N);
    dfs(0,0LL,G);

    // REP(i,N) cout << dp[i] << " ";
    // cout << endl;

    REP(i,60) {
        ll cnt1 = 0;
        ll cnt0 = 0;
        REP(j,N) {
            if((dp[j]>>i)&1) cnt1++;
            else cnt0++;
        }
        ans += (cnt1*(cnt0))%MOD * (modpow(2,i,MOD));
        ans %= MOD;
    }
    ans %= MOD;

    cout << ans << endl;
    return 0;
}