#include <cstdio>
#include <cctype>
#define int long long
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
inline long long read (void) {
	long long x = 0; int f = 1, ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
	while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int maxn = 200005;
int tot_edge, head[maxn], to[maxn<<1], link[maxn<<1];
long long weight[maxn<<1], a[maxn], ans;
int b[65];
inline void add_edge (int x, int y, long long w) {
	to[++tot_edge] = y;
	link[tot_edge] = head[x];
	weight[tot_edge] = w;
	head[x] = tot_edge;
}
void dfs (int x, int f = 0) {
	for(int now = head[x]; now; now = link[now]) {
		if(to[now] == f) continue;
		a[to[now]] = a[x] ^ weight[now];
		dfs (to[now], x);
	}
}
signed main (void) {
	int n = read();
	FOR(i,2,n) {
		int x = read(), y = read(); long long w = read();
		add_edge (x, y, w);
		add_edge (y, x, w);
	}
	dfs (1);
	for(int i=n; i>=1; --i)
		for(int j=0; j<60; ++j)
			if((1ll<<j) & a[i]) ++ b[j];
	for(int i=1; i<=n; ++i)
		for(int j=0; j<60; ++j)
			if((1ll<<j) & a[i]) ans = (ans + (1ll<<j) % 1000000007 * (n-i- --b[j])) % 1000000007;
			else ans = (ans + (1ll<<j) % 1000000007 * b[j]) % 1000000007;
	printf("%lld\n", ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//indexed set is using "int" here--------- use ll ...
// typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ve <ll> exor,parent;
map <pair<ll,ll>,ll> wt;
void dfs(ll node, ve<pair <ll,ll>> adj[], ve<bool> &visited)
{
    visited[node] = true;
    // do stuff
    exor[node]=exor[parent[node]]^wt[{parent[node],node}];
    for (int i = 0; i < (int)adj[node].size(); i += 1)
    {
        if (!visited[adj[node][i].first])
        {
            parent[adj[node][i].first]=node;
            dfs(adj[node][i].first, adj, visited);
        }
    }
}
long long int sumXOR(ve <ll> arr, ll n)
{
    ll sum = 0;
    ll one =1;
    for (int i = 0; i < 61; i++) 
    {
        //  Count of zeros and ones
        ll zc = 0, oc = 0; 
          
        // Individual sum at each bit position
        long long int idsum = 0; 
        for (int j = 0; j < n; j++)
        {
            if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;
        }
          
        // calculating individual bit sum 
        idsum = (((oc%rem) * (zc%rem))%rem * ((one << i)%rem))%rem; 
  
        // final sum    
        sum += idsum; 
        sum%=rem;
    }
    return sum;
}
int main()
{
    FAST;
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin >> n;
    exor.assign(n+1,0);
    parent.assign(n+1,0);
    ve<pair<ll, ll>> adj[n + 1];
    rep(i, 0, n - 1)
    {
        ll u, v, w;
        cin >> u >> v >> w;
        wt[{u,v}]=w;
        wt[{v,u}]=w;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    ve <bool> visit(n+1,false);
    dfs(1,adj,visit);
    ll sum=0;
    rep (i,1,n+1)
    {
        sum+=exor[i];
    }
    ve <ll> v1(n);
    rep (i,1,n+1)
    {
        v1[i-1]=exor[i];
    }
    ll ans=sumXOR(v1,n);
    cout<<ans<<"\n";
}
