#include<bits/stdc++.h>
#define int long long
#define N 200005
#define MOD 1000000007
using namespace std;
int n,d[N],ans;
vector<int> to[N],w[N];
void add(int u,int v,int wt){to[u].push_back(v),w[u].push_back(wt);}
void dfs(int u,int fa){
	for(int i=0,v;i<to[u].size();i++)
		if((v=to[u][i])!=fa)d[v]=d[u]^w[u][i],dfs(v,u);
}
signed main(){
	cin>>n;
	for(int i=1,u,v,wt;i<n;i++)scanf("%lld%lld%lld",&u,&v,&wt),add(u,v,wt),add(v,u,wt);
	dfs(1,0);
	for(int k=0;k<60;k++){
		int a=0;
		for(int i=1;i<=n;i++)a+=((d[i]>>k)&1);
		ans=(ans+a*(n-a)%MOD*((1ll<<k)%MOD)%MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}
#include <bits/stdc++.h> 
using namespace std; 

#define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++) 
#define rfor(i, a, b) for (int i = (int) a ; i >= b ; i--)  

#define vec vector 
#define PB push_back 

#define MP make_pair 
#define MT make_tuple 
#define F first 
#define S second 

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs> 
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

template <typename T1, typename T2> 
inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {
    return os << "(" << p.F << ", " << p.S << ")";
}

template <typename T> 
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T> 
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T> 
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V> 
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}
////////////////////////////////////////////////////////////////////////

template <ll mod> 
class modular_int {
    private:
    ll x;

    public:
    modular_int(ll y) : x( (y % mod + mod) % mod) {}
    modular_int() : x(0LL) {}

    ll rpr() const { return x; }

    modular_int<mod>& operator += (const modular_int<mod>& rhs) {
        x = (x + rhs.x) % mod;
        return *this;
    }

    friend modular_int<mod> operator + (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs += rhs;
        return lhs;
    }

    modular_int<mod>& operator *= (const modular_int<mod>& rhs) {
        x = (x * rhs.x) % mod;
        return *this;
    }

    friend modular_int<mod> operator * (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs *= rhs;
        return lhs;
    }

    modular_int<mod>& operator -= (const modular_int<mod>& rhs) {
        x = ((x - rhs.x) % mod + mod) % mod;
        return *this;
    }

    friend modular_int<mod> operator - (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs -= rhs;
        return lhs;
    }
};

const ll MOD = 1e9 + 7;
using mint = modular_int<MOD>;

////////////////////////////////////////////////////////////////////////

using edge = pair<int, ll>;

int N;
vec<vec<edge>> g;
vec<ll> d;

void bfs() {
    d.assign(N+1, -1);
    queue<edge> q;
    q.push({1,0});
    d[1] = 0;
    while(!q.empty()) {
        auto [u, pw] = q.front(); q.pop();
        for(auto [v, w] : g[u]) {
            if(d[v] != -1) continue;
            d[v] = pw ^ w;
            q.push({v, d[v]});
        }
    }
}


////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;
    g.assign(N+1, vec<edge>());
    ffor(i, 1, N) {
        int u, v; ll w;
        cin >> u >> v >> w;
        g[u].PB({v, w});
        g[v].PB({u, w});
    }

    bfs();
    //debug("d=", d);
    mint ans(0LL);
    ffor(k, 0, 60) {
        mint p(1LL << k);
        ll ones = 0LL, zeros = 0LL;
        ffor(u, 1, N) {
            if(d[u] & (1LL << k)) {
                ones++;
            }
            else {
                zeros++;
            }
        }
        ans += p * mint(ones) * mint(zeros);
        //debug(k, ones, zeros, ans.rpr());
    }
    cout << ans.rpr() << "\n";
}

