#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

struct edge{
    ll to;
    ll c;
};

vector<edge> g[210000];
VI sum(210000,0);
ll s=0;

void dfs(int v, int p){
    sum[v]=s;
    for(auto i:g[v]){
        if(i.to!=p){
            s^=i.c;
            dfs(i.to,v);
            s^=i.c;
        }
    }
}

int main(){
    int n; cin >> n;
    ll a, b, c;
    REP(i,n-1){
        cin >> a >> b >> c;
        a--, b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    dfs(0,-1);
    VI cnt(60,0);
    REP(i,n){
        ll x=sum[i];
        REP(j,60){
            if(x&1)
                cnt[j]++;
            x>>=1;
        }
    }
    ll ans=0;
    ll p=1;
    REP(i,60){
        ans+=cnt[i]*(n-cnt[i])%MOD*p%MOD;
        ans%=MOD;
        p=p*2%MOD;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<pair<int, long long int>>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    long long int w;
    cin >> u >> v >> w;
    u--;
    v--;
    pair<int, long long int> p = make_pair(v, w), q = make_pair(u, w);
    G.at(u).push_back(p);
    G.at(v).push_back(q);
  }
  vector<long long int> dist(N, -1);
  queue<int> que;
  que.push(0);
  dist.at(0) = 0;
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int i = 0; i < G.at(u).size(); i++) {
      int v = G.at(u).at(i).first;
      if (dist.at(v) >= 0) continue;
      long long int w = G.at(u).at(i).second;
      dist.at(v) = dist.at(u) ^ w;
      que.push(v);
    }
  }
  long long int ans = 0, MOD = 1000000007;
  for (int k = 0; k < 60; k++) {
    vector<long long int> cnt(2, 0);
    for (int i = 0; i < N; i++) cnt.at((dist.at(i) >> k) & 1)++;
    ans += ((long long int)1 << k) % MOD * cnt.at(0) % MOD * cnt.at(1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}