#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a; i<b; i++)
#define fr(i,a,b) for(int i=a; i>=b; i--)
#define fll(i,a,b) for(ll i=a; i<b; i++)
#define frll(i,a,b) for(ll i=a; i>=b; i--)
typedef vector<int> vi;
typedef long long int ll;
typedef vector<ll> vll;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI 3.1415926535
ll Mod = 1e9+7;
ll N = 1e5;

// ll Mod = 998244353;

// ll mult(ll a, ll b, ll mod = Mod) {
//     ll ret = 1;
//     ret = ((a%mod) * (b%mod))%mod;
//     return ret;
// }

// ll pow(ll a, ll b, ll mod = Mod-2) {
//     if(b == 0) return 1;
//     ll ret = 1;
//     while(b) {
//         if(b&1) {
//             ret = mult(ret,a,mod);
//         }
//         a = mult(a,a,mod);
//         b>>=1;
//     }
//     return ret;
// }

// ll sub(ll a, ll b) {
//     ll ret = (a%Mod - b%Mod + Mod)%Mod;
//     return ret;
// }

// void seive(vector<bool> &status) {
//      f(i,2,2e6+1) {
//          if(status[i]) {
//                 for(ll j = i*i; j<=2e6; j+=i) status[j] = 0;
//          }
//      }
//  }

// int getmex(vi& occr, int n, int mex) {
//     for(int i = mex; i<n; i++) {
//         if(occr[i] == 0) return i;
//     }
//     return n;
// }

// void swap(int &a, int &b) {
//     a = a + b;
//     b = a - b; 
//     a = a - b;
// }

// int gcd(int a, int b) {
//     if(b == 0) return a;
//     return gcd(b,a%b);
// }

void test_case() {
    int n,u,v;
    ll w;
    cin>>n;
    vector<vector<int>> tree(n+1);
    vector<vector<ll>> wt(n+1);
    f(i,0,n-1) {
        cin>>u>>v>>w;
        tree[v].push_back(u);
        tree[u].push_back(v);
        wt[v].push_back(w);
        wt[u].push_back(w);
    }

    queue<int> q;
    q.push(1);
    ll dist[n+1];
    memset(dist, -1, sizeof dist);
    dist[1] = 0;
    while(!q.empty()) {
        int p = q.front();
        q.pop();
        f(i,0,tree[p].size()) {
            int x = tree[p][i];
            ll w = wt[p][i];
            if(dist[x] == -1) {
                dist[x] = dist[p]^w;
                q.push(x);
            }
        }
    }

    ll ans = 0;
    f(i,0,60) {
        ll up = 0, lo = 0;
        f(j,1,n+1) {
            if((dist[j]>>i)&1) up++;
            else lo++;
        } 
        ans = (ans + ((1LL<<i)%Mod*((up*lo)%Mod))%Mod)%Mod;
    }

    cout<<ans<<'\n';

}


int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    fastio;
    // vector<bool> status(2e6+1,1);
    int t = 1;
    // vi primes;
    // seive(status);
    // f(i,2, 2e6+1) {
    //     if(i > 5000) {
    //         break;
    //     }
    //     if(status[i]) primes.push_back(i);
    // } 
    // cin>>t;

    while(t--) {
        test_case();
    }
    
}
#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
#define int long long

const int nax = 200001;
vector<int> graph[nax];
vector<int> weight[nax];

int32_t main() {
	int n; 
	scanf("%lld", &n);
	for(int i = 0; i < n - 1; ++i){
		int u, v, w; 
		scanf("%lld %lld %lld", &u, &v, &w);
		graph[u].push_back(v);
		graph[v].push_back(u);
		weight[u].push_back(w);
		weight[v].push_back(w);
	}
	int dist_from_root[n + 1] = {0};
	function<void(int, int, int)> dfs = [&] (int vertex, int parent, int curr){
		dist_from_root[vertex] = curr;
		for(int i = 0; i < (int)graph[vertex].size(); ++i){
			int child = graph[vertex][i];
			int node_weight = weight[vertex][i];
			if(child == parent)
				continue;
			dfs(child, vertex, curr^node_weight);
		}
	};
	dfs(1, 0, 0);
	int track_bits[60] = {0};
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < 60; ++j){
			if((dist_from_root[i] & (1ll << j))) ++track_bits[j];
		}
	}
	int ans = 0;
	int MOD = 1e9 + 7;
	for(int i = 0; i < 60; ++i){
		int value = ((track_bits[i] % MOD) * ((n - track_bits[i]) % MOD)) % MOD * ((1ll << i) % MOD);
		value = value % MOD;
		ans = ans + value;
		ans = (ans + MOD) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}
