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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

int n;
const int N = 2e5+10;
vector<pair<int,ll>> g[N];
ll ib;
ll n0;
void dfs(int no, int from, int cor){
	if(cor==0) n0++;
	for(auto &[it,c] : g[no]){
		if(it==from) continue;
		int cc = cor;
		if(c&(1ll<<ib)) cc = !cc;
		dfs(it,no,cc);
	}
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	fr(i,n-1){
		int a, b; ll w; cin >> a >> b >> w; a--,b--;
		g[a].emplace_back(b,w);
		g[b].emplace_back(a,w);
	}
	ll mod = round(1e9)+7;
	ll ans = 0;
	fr(ii,63){
		ib = ii;
		n0 = 0;
		dfs(0,-1,0);
		ans = (ans+n0*(n-n0)%mod*((1ll<<ib)%mod)%mod)%mod;
	}
	cout << ans << "\n";
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z = 0, mod = 1000000007, MAX = 60;

int main(){
  ll N;
  cin >> N;
  
  vector<vector<pair<ll, ll>>> G(N + 1, vector<pair<ll, ll>>(0));
  for (ll i = 0; i < N - 1; i++){
    ll u, v, w;
    cin >> u >> v >> w;
    
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  
  ll root;
  for (ll i = 1; i <= N; i++){
    if (G[i].size() == 1){
      root = i;
      break;
    }
  }
  
  queue<ll> que;
  que.push(root);
  vector<vector<ll>> ev(MAX, vector<ll>(N + 1, -1));
  for (ll i = 0; i < MAX; i++){
    ev[i][root] = 0;
  }
  
  while (!que.empty()){
    ll tar = que.front();
    que.pop();
    
    for (pair<ll, ll> next : G[tar]){
      if (ev[0][next.first] != -1) continue;
      
      ll nw = next.second;
      for (ll i = 0; i < MAX; i++){
        if (nw % 2 == 1){
          ev[i][next.first] = ev[i][tar] ^ 1;
        }
        else{
          ev[i][next.first] = ev[i][tar];
        }
        nw /= 2;
      }
      
      que.push(next.first);
    }
  }
  
  ll ans = 0, base = 1;
  for (ll i = 0; i < MAX; i++){
    ll e = 0, o = 0;
    for (ll j = 1; j <= N; j++){
      if (ev[i][j] == 1){
        e++;
      }
      else{
        o++;
      }
    }
    
    ans += (((e * o) % mod) * base) % mod;
    ans %= mod;
    base *= 2;
    base %= mod;
    //cout << i << ' ' << e << ' ' << o << endl;
  }
  
  cout << ans << endl;
}