#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
const ll MOD = 1e9+7;
//int eo[64][MAX_N];
bool vis[64][MAX_N];
map<P, ll> mp;

struct edge
{
	int to;
	ll cost;
};

vector<edge> G[MAX_N];
int cntEO[2] = {0,0};

void dfs(int n, int eo, int keta)
{
	vis[keta][n] = true;
	//if (keta == 0) cout << "visiting:" << n << endl;
	rep(i,G[n].size())
	{
		if (!vis[keta][G[n][i].to])
		{
			if ((G[n][i].cost >> keta) & 1)
			{
				cntEO[(eo+1)%2]++;
				dfs(G[n][i].to, (eo+1)%2, keta);
			}
			else
			{
				cntEO[eo]++;
				dfs(G[n][i].to, eo, keta);
			}
		}
	}
	return;
}


int main()
{
	int N;
	cin >> N;
	rep(i,N-1)
	{
		int u,v;
		ll w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(edge{v,w});
		G[v].push_back(edge{u,w});
		mp[P(u,v)] = w;
		mp[P(v,u)] = w;
	}

	ll ans = 0;
	for (int i = 0; i < 62; ++i)
	{
		//cout << "a";
		cntEO[0] = 1, cntEO[1] = 0;
		dfs(0,0,i);
		ans = (ans + (1ull << i) % MOD * cntEO[0] % MOD * cntEO[1] % MOD) % MOD;
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 1000000007;
//998244353;
void randinit(){srand((unsigned)time(NULL));}
ll modpow(ll A,ll B,ll M){
    ll r = 1,p = A;
    while(B > 0){
        if(B % 2 == 1) r = (r * p) % M;
        p = (p * p) % M;
        B /= 2;
    }
    return r;
}
ll modinv(ll A,ll M){
    //A*r+B*n=gcd(A,B)
    A %= M;
    if(A == 0 || __gcd(A,M) != 1){
        //cout << "Error modinv(" << A << "," << M << ")" << endl;
        return -1;
    }
    ll B = M,U = 1,V = 0;
    while(B){
        ll T = A / B;
        A -= T * B;
        swap(A,B);
        U -= T * V;
        swap(U,V);
    }
    U %= M;
    if(U < 0) U += M;
    return U;
}
int main(){
    ll N;
    cin >> N;
    vector<vector<tuple<ll,ll>>> G(N);
    for(ll i = 0;i < N - 1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        G[a - 1].emplace_back(make_tuple(b - 1,c));
        G[b - 1].emplace_back(make_tuple(a - 1,c));
    }
    ll ans = 0;
    for(ll i = 0;i < 61;i++){
        queue<tuple<bool,ll>> que;
        vector<ll> D(N,-1);
        que.push(make_tuple(0,0));
        while(!que.empty()){
            ll a = get<0>(que.front()),b = get<1>(que.front());
            que.pop();
            if(D[b] == -1){
                D[b] = a;
                for(ll j = 0;j < G[b].size();j++){
                    ll c = get<0>(G[b][j]),d = get<1>(G[b][j]);
                    if(D[c] == -1){
                        if(d & (1LL << i)){
                            que.push(make_tuple((a + 1) % 2,c));
                        }
                        else{
                            que.push(make_tuple(a,c));
                        }
                    }
                }
            }
        }
        ll a = 0,b = 0,c = 0;
        for(ll j = 0;j < N;j++){
            if(D[j] == 0) a++;
            else b++;
        }
        for(ll j = 0;j < N;j++){
            if(D[j] == 0) c = (c + b) % MOD;
            else c = (c + a) % MOD;
        }
        ans = (ans + ((c * modpow(2,i,MOD)) % MOD)) % MOD;
    }
    cout << (ans * modinv(2,MOD)) % MOD << endl;
}
