#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <functional>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define REP(i,n) for (ll i = 1; i <= (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vt vector
#define fcout cout<<fixed<<setprecision(15)
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078160628620899
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1000000000000000000;
const ll NIL = -1;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { 1,0,-1,0 };

ll N;
ll dist[200010];
tuple<ll, ll, ll> U[100010];
vector<pair<ll,ll>> adj[200010];

void dfs(ll x, uint64_t d) {
	for (auto u : adj[x]) {
		if (dist[u.first] == -1) {
			ll p = d ^ u.second;
			dist[u.first] = p;
			dfs(u.first, p);
		}
	}
}

int main() {
	cin >> N;
	rep(i, N - 1) {
		ll A, B;
		ll C;
		cin >> A >> B >> C;
		A--; B--;
		pair<ll, ll> As = { B,C }, Bs = { A,C };
		adj[A].pb(As);
		adj[B].pb(Bs);
	}
	dist[0] = 0;
	for (ll i = 1; i < N; i++) dist[i] = -1;
	dfs(0, 0);
	ll ANS = 0;
	ll now = 1;
	for (ll i = 0; i < 60; i++) {
		ll cnt = 0;
		for (ll j = 0; j < N; j++) {
			if (dist[j] % 2 == 1) cnt++;
			dist[j] /= 2;
		}
		ll plus = cnt * (N - cnt);
		plus %= MOD;
		plus *= now;
		plus %= MOD;
		ANS += plus;
		ANS %= MOD;
		now *= 2;
		now %= MOD;
	}
	cout << ANS << endl;
	return 0;
}
#include<bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int maxn=2e5+10;
const int mb=60;
vector<pair<int,ll> >vect[maxn];
ll dp[maxn][mb][2],rez,mod=1e9+7;

void go(int x,int prv){

    for(int i=0;i<vect[x].size();i++){

        int id=vect[x][i].ff;
        ll w=vect[x][i].ss;
        if(id==prv)continue;
        go(id,x);

        for(int j=0;j<mb;j++){

            if((1ll<<(j))&w)swap(dp[id][j][0],dp[id][j][1]);

            rez=(rez+((1ll<<j)%mod)*dp[id][j][1] )%mod;

            rez=(rez+((((1ll<<j)%mod)*dp[x][j][1])%mod)*dp[id][j][0] )%mod;
            rez=(rez+((((1ll<<j)%mod)*dp[x][j][0])%mod)*dp[id][j][1] )%mod;

            dp[x][j][0]+=dp[id][j][0];
            dp[x][j][1]+=dp[id][j][1];
        }

    }
    for(int j=0;j<mb;j++)
    dp[x][j][0]++;
}

int main(){

    ///freopen("test.txt","r",stdin);

    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int u,v;
        ll w;
        scanf("%d %d %lld",&u,&v,&w);
        vect[u].pb({v,w});
        vect[v].pb({u,w});
    }

    go(1,0);

    printf("%lld\n",rez);

return 0;
}
