#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pil pair<int,ll>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 200005
#define m 61
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
#define memset1(v) memset(v,-1,sizeof(v))
#define memset0(v) memset(v,0,sizeof(v))
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n;
ll res[m];
ll c[N][m][2];
vector<pil>ed[N];
void dfs(int u,int pa){
	for(int i=0;i<m;i++)c[u][i][0]=1;
	for(pil p:ed[u]){
		int v=p.fi;
		ll w=p.se;
		if(pa==v)continue;
		dfs(v,u);
		for(ll i=0;i<m;i++){
			if((w>>i)&1){
				mad(res[i],c[v][i][0]*c[u][i][0]);
				mad(res[i],c[v][i][1]*c[u][i][1]);
				mad(c[u][i][0],c[v][i][1]);
				mad(c[u][i][1],c[v][i][0]);
			}
			else{
				mad(res[i],c[v][i][0]*c[u][i][1]);
				mad(res[i],c[v][i][1]*c[u][i][0]);
				mad(c[u][i][0],c[v][i][0]);
				mad(c[u][i][1],c[v][i][1]);
			}
		}
	}
}
void solve(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v;
		ll w;
		cin>>u>>v>>w;
		ed[u].pb(pil(v,w));
		ed[v].pb(pil(u,w));
	}
	dfs(1,0);
	ll ans=0;
	for(ll i=0;i<m;i++)mad(ans,res[i]*((1ll<<i)%mod));
	cout<<ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<ll,ll>;
// #include"debug.hpp"

void calc(vector<ll> A)
{
	const ll M = 60;
	const ll mod = 1e9 + 7;
	ll n = A.size();
	vector<ll> dig(M);
	for(ll i = 0; i < n; i++) {
		ll a = A[i];
		for(ll j = 0; j < M; j++) if((1LL<<j) & (a))dig[j]++;
	}
 
	ll sum = 0;
	for(ll i = 0; i < M; i++) {
		ll num = (ll)dig[i] * (n - dig[i]) % mod;
		(num *= (1LL<<i) % mod) %= mod;
		(sum += num) %= mod;
	}

	cout << sum << endl;
 
}


vector<vector<pair<ll,ll>>> tre;
vector<ll> num;

void dfs(ll v, ll par, ll sum) {
	num[v] = sum;
	for(auto [i, len] : tre[v]) {
		if(i == par)continue;
		dfs(i, v, sum xor len);
	}

}

int main()
{
	ll N; cin >> N;
	tre.resize(N);
	num.resize(N);

	for(ll i = 0; i < N - 1; i++) {
		ll u, v, k; cin >> u >> v >> k;
		u--,v--;
		tre[u].push_back({v, k});
		tre[v].push_back({u, k});
	}

	dfs(0, -1, 0);
	// print(num);
	calc(num);

}