#include <bits/stdc++.h>
#define PB push_back
#define MP(x,y) make_pair(x,y)
#define F first
#define S second
#define loop(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rloop(i,m,n) for(int i=(int)(m) ; i > (int) (n) ; --i )
#define lp(i,n) loop(i,0,n)
#define rlp(i,n) rloop(i,n,0)
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
int main(){
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int N;
    scanf("%d", &N);
    vector<pair<int, lli> > edges[N];
    int u, v;
    lli w;
    lp(i, N-1) {
        scanf("%d%d%lld", &u, &v, &w);
        --u; --v;
        edges[u].PB(MP(v,w));
        edges[v].PB(MP(u,w));
    }
    vector<lli> XOR(N);
    vector<bool> visited(N, false);
    queue<pair<int, lli> > q;
    lli d;
    q.push(MP(0, 0));
    visited[0] = true;
    while (!q.empty()) {
        u = q.front().F;
        d = q.front().S;
        q.pop();
        XOR[u] = d;
        for(vector<pair<int, lli> >::iterator it = edges[u].begin(); it != edges[u].end(); ++it) {
            v = it->F;
            w = it->S;
            if (visited[v]) continue;
            visited[v] = true;
            q.push(MP(v, d^w));
        }
    }
    lli ans = 0, add, cnt;
    lp(bit, 60) {
        cnt = 0;
        lp(i, N)
            if (XOR[i]&(((lli)1)<<bit)) ++cnt;
        add = ((((lli)1)<<bit)%mod)*cnt;
        add %= mod;
        add = add * (N-cnt);
        add %= mod;
        // printf("%d %lld %lld\n", bit, cnt, add);
        ans += add%mod;
        ans %= mod;
    }
    // lp(i, N) {
    //     loop(j, i+1, N) {
    //         ans += XOR[i]^XOR[j];
    //         ans %= mod;
    //     }
    // }
    printf("%lld", ans);
    return 0;
}

/*
 *
 *   1 0 0 1 1 0 A
 *   0 0 1 1 0 1 B
 *
 *   1 0 1 0 1 1 A ^ B
 *   1 0 0 1 1 0 A
 * 1 0 1 0 0 0 1 A + A^B
 *
 * 0 0 1 1 0 1 0 2B
 *
 * 1 0 0 1 1 0 0 2A
 *
 *
 * 010
 * 011
 * 001
 *
 * 001
 * 011
 * 010
 *
 */

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

#ifdef LOCAL
#include <debugger.h>
#else
#define dbg(x...) {}
#define dbg_t()   {}
#endif

using ll = long long;
using ld = long double;

const ll INF = 1e18;


const ll MOD = 1e9+7; 

namespace mod_op
{
  ll madd(ll a, ll b) 
  {
    return (a + b) % MOD;
  }

  ll mmul(ll a, ll b) 
  {
    return ((a % MOD) * (b % MOD)) % MOD;
  }

  ll msub(ll a, ll b) 
  {
    return (((a - b) % MOD) + MOD) % MOD;
  }

  ll mpow(ll a, ll b) 
  {
    a %= MOD;
    ll res = 1;
    while (b > 0) 
    {
      if (b & 1) 
        res = mmul(res, a);
      a = mmul(a, a);
      b >>= 1;
    }
    return res;
  }

  ll minv(ll a) 
  {
    return mpow(a, MOD - 2);
  }

  ll mdiv(ll a, ll b) 
  {
    return mmul(a, minv(b));
  }
}

using namespace mod_op;

void solve()
{
  ll n; cin >> n;

  vector<vector<array<ll, 2>>> graph(n);

  for (ll i = 0; i < n - 1; i++)
  {
    ll u, v, w; cin >> u >> v >> w;
    u--; v--; 
    graph[u].push_back({v, w}); 
    graph[v].push_back({u, w}); 
  } 

  vector<ll> c(n, 0);

  function<void(ll, ll)> dfs = [&](ll v, ll p)
  {
    for (auto x: graph[v])
    {
      if (x[0] != p)
      {
        c[x[0]] ^= (x[1] ^ c[v]);
        dfs(x[0], v);
      }
    }
  };

  dfs(0, -1);

  ll ans = 0;

  vector<vector<ll>> v(n, vector<ll>(62, 0)); 

  for (ll i = 0; i < n; i++)
  {
    bitset<62> bs(c[i]);
    for (ll j = 0 ; j < 62; j++)
    {
      v[i][j] = (bs[j] == 1);
      if (i > 0)
      {
        v[i][j] += v[i - 1][j];
        if (bs[j] == 1)
          ans = madd(ans, mmul(i - v[i - 1][j], mpow(2, j)));
        else
          ans = madd(ans, mmul(v[i - 1][j], mpow(2, j)));
      }
    }
  }

  cout << ans << "\n";
}


signed main()
{  
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll _t = 1;
  // cin >> _t;
  for (ll i = 1; i <= _t; i++)
  {
    // cout << "Case #" << i << ": ";
    solve();
  }

  dbg_t();
  
  return 0;
}     
     
