#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

// {{{ModInt
template <int modulo>
class ModInt {
 public:
  ModInt() : val_(0) {}

  ModInt(int v) {
    val_ = v % modulo;
    if (val_ < 0) val_ += modulo;
  }

  ModInt(long long v) {
    val_ = v % modulo;
    if (val_ < 0) val_ += modulo;
  }

  inline int val() const { return val_; }

  ModInt& operator++() {
    ++val_;
    if (val_ == modulo) val_ = 0;
    return *this;
  }

  ModInt& operator--() {
    if (val_ == 0) val_ = modulo;
    --val_;
    return *this;
  }

  ModInt operator++(int) {
    auto ret = *this;
    ++*this;
    return ret;
  }

  ModInt operator--(int) {
    auto ret = *this;
    --*this;
    return ret;
  }

  ModInt& operator+=(const ModInt& o) {
    val_ += o.val_;
    if (val_ >= modulo) val_ -= modulo;
    return *this;
  }

  ModInt& operator-=(const ModInt& o) {
    val_ -= o.val_;
    if (val_ < 0) val_ += modulo;
    return *this;
  }

  ModInt& operator*=(const ModInt& o) {
    val_ = (1ll * val_ * o.val_) % modulo;
    return *this;
  }

  ModInt& operator/=(const ModInt& o) { return *this *= o.Recip(); }

  ModInt Pow(long long n) const {
    ModInt a = *this;
    ModInt res(1);
    while (n > 0) {
      if (n & 1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }

  ModInt Recip() const { return Pow(modulo - 2); }

  friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) += rhs;
  }

  friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) -= rhs;
  }

  friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) *= rhs;
  }

  friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) {
    return ModInt(lhs) /= rhs;
  }

  friend bool operator==(const ModInt& lhs, const ModInt& rhs) {
    return lhs.val_ == rhs.val_;
  }

  friend bool operator!=(const ModInt& lhs, const ModInt& rhs) {
    return lhs.val_ != rhs.val_;
  }

 private:
  int val_;
};
// }}}

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)((v).size())
using i64 = long long;
using mint = ModInt<(int)1e9 + 7>;

vector<vector<pair<int, i64>>> g;
int n;
vector<i64> cumXor;

void dfs(int v, int p = -1, i64 xr = 0) {
  cumXor[v] = xr;
  for (auto [u, w] : g[v]) {
    if (u != p) {
      dfs(u, v, xr ^ w);
    }
  }
}

void solve() {
  scanf("%d", &n);
  g.assign(n, {});
  cumXor.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    i64 w;
    scanf("%d%d%lld", &u, &v, &w);
    --u; --v;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }
  dfs(0);

  mint ans = 0;
  i64 p2 = 1;
  for (int l = 0; l < 60; ++l) {
    int ones = 0, zeros = 0;
    for (i64 x : cumXor) {
      if ((x >> l) & 1) {
        ones++; 
      } else {
        zeros++;
      }
    }

    for (i64 x : cumXor) {
      if ((x >> l) & 1) {
        ans += mint(zeros) * mint(p2);
      } else {
        ans += mint(ones) * mint(p2);
      }
    }
    p2 *= 2;
  }
  cout << (ans / 2).val() << endl;
}

int main() {
  solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
 
#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int> 
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
vector<pa>g[1000001];
ll dp[1000001];
void dfs(ll v,ll par=-1)
{
        for(pa d:g[v])
        {
                if(d.first-par)
                {
                      dp[d.first]=dp[v]^d.second;
                      dfs(d.first,v);
                }
        }
}
void solve()
{
        ll n;
        cin>>n;
        f(i,n-1)
        {
             ll x,y,w;
             cin>>x>>y>>w;
             x--,y--;
             g[x].pb({y,w});
             g[y].pb({x,w});
        }
        dfs(0);
        ll ans=0;
        f(j,61)
        {
                ll ones,zeros;
                ones=zeros=0;
                f(i,n)
                {
                        if(dp[i]&(1ll<<j))
                        {
                                ones++;
                        }
                        else
                        {
                                zeros++;
                        }
                }
                zeros*=ones;
                zeros%=mod;
                ans+=((1ll<<j)%mod*zeros%mod);
                ans%=mod;
        }
        cout<<ans<<endl;
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	  solve();
	// }
	return 0;
}