#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
// avoid unordered_map and unordered_set!!!
#include <vector>
#include <utility>

using namespace std;

using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;

#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;

#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif

constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;

template<i64 mod>
class modint_t
{
public:
    modint_t() : val_(0) {}
    // not explicit
    modint_t(const i64 x) : val_(((x % mod) + mod) % mod) {}

    modint_t& operator+=(const modint_t& o) { val_ += o.val_; val_ %= mod; return *this; }
    modint_t& operator*=(const modint_t& o) { val_ *= o.val_; val_ %= mod; return *this; }

    // only use if mod is prime!!!
    static modint_t inv(const modint_t& x)
    {
        modint_t<mod> acc(1);
        modint_t<mod> curpow(*x);
        for (i64 e = mod - 2; e; e >>= 1, curpow *= curpow)
        {
            if (e & 1)
            {
                acc *= curpow;
            }
        }
        return acc;
    }

    i64 operator*() const { return val_; }

private:
    i64 val_;
};

void
dfs(const i64 u, const i64 p, const vec<vec<pi64>>& adj, vec<i64>& dists, const i64 ancestor_edge_wt_xor = 0)
{
    dists[u] = ancestor_edge_wt_xor;
    for (let auto [child, w] : adj[u])
    {
        if (child == p)
        {
            continue;
        }
        dfs(child, u, adj, dists, ancestor_edge_wt_xor ^ w);
    }
}

int
main()
{
    ios_base::sync_with_stdio(false);
    // fast io: see 1423K
    cin.tie(nullptr);
    cout.tie(nullptr);

    DRi64(N);
    vec<vec<pi64>> adj(N + 1);
    for (i64 i = 0; i + 1 < N; ++i)
    {
        DRi64(U); DRi64(V); DRi64(W);
        adj[U].emplace_back(V, W);
        adj[V].emplace_back(U, W);
    }

    vec<i64> dists(N + 1);
    dfs(1, -1, adj, dists);

    modint_t<MOD> acc;
    for (i64 bitpos = 0; bitpos < 60; ++bitpos)
    {
        let i64 mask = 1LL << bitpos;
        i64 num_on = 0;
        for (i64 i = 1; i <= N; ++i)
        {
            num_on += !!(dists[i] & mask);
        }
        modint_t<MOD> tmp(mask);
        tmp *= num_on * (N - num_on);
        acc += tmp;
    }

    cout << *acc << "\n";

    return 0;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

class ModInt{
    public:
    ll v;
    ModInt(ll _v = 0){
        if(_v >= MOD) _v %= MOD;
        v = _v;
    }
    ModInt operator+(ll n){
        return ModInt((v+n)%MOD);
    }
    ModInt operator-(ll n){
        return ModInt((v-n+MOD)%MOD);
    }
    ModInt operator*(ll n){
        if(n >= MOD) n %= MOD;
        return ModInt((v*n)%MOD);
    }
    ModInt operator/(ll n){
        return ModInt((ModInt(n).inv()*v).v%MOD);
    }

    void operator+=(ll n){
        v = (v+n)%MOD;
    }
    void operator-=(ll n){
        v = (v-n+MOD)%MOD;
    }
    void operator*=(ll n){
        v = (v*n+MOD)%MOD;
    }
    
    
    ModInt operator+(ModInt n){
        return ModInt((v+n.v)%MOD);
    }
    ModInt operator-(ModInt n){
        return ModInt((v-n.v+MOD)%MOD);
    }
    ModInt operator*(ModInt n){
        return ModInt((v*n.v)%MOD);
    }
    ModInt operator/(ModInt n){
        return ModInt((n.inv()*v).v%MOD);
    }

    void operator+=(ModInt n){
        v = (v+n.v)%MOD;
    }
    void operator-=(ModInt n){
        v = (v-n.v+MOD)%MOD;
    }
    void operator*=(ModInt n){
        v = (v*n.v)%MOD;
    }

    void operator=(ModInt n){
        v = n.v;
    }
    bool operator==(ModInt n){
        return v == n.v;
    }
    bool operator!=(ModInt n){
        return v != n.v;
    }
    void operator=(ll n){
        v = n%MOD;
    }

    ModInt inv(){
        if(v == 1) return ModInt(1);
        else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD);
    }
};

ostream& operator<<(ostream& os, const ModInt& m){
    os << m.v;
    return os;
}

istream & operator >> (istream &in,  ModInt &m){
    in >> m.v;
    return in;
}

int ch[200000];
bool used[200000];
ll xo[200000];

struct edge{
    int to;
    ll cost;
};

vector<edge> g[200000];
using mint = ModInt;

void dfs(int v, ll x){
    used[v] = true;
    ch[v]++;
    xo[v] = x;
    for(edge e : g[v]){
        if(!used[e.to]){
            dfs(e.to, x^e.cost);
            ch[v] += ch[e.to];
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    for(int i = 0; i < n-1; i++){
        int u, v; ll w; cin >> u >> v >> w; u--; v--;
        g[v].push_back(edge{u, w});
        g[u].push_back(edge{v, w});
    }
    dfs(0, 0);
    mint ans = mint(0);
    for(int j = 0; j < 60; j++){
        ll cnt = 0;
        for(int i = 0; i < n; i++){
            if(xo[i]&(1ll<<j)) cnt++;
        }
        ans += mint(1ll<<j)*cnt*(n-cnt);
    }
    cout << ans << endl;
}