#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

template<unsigned MOD_> struct ModInt {
    static constexpr unsigned MOD = MOD_;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

    ModInt inv() const { return pow(MOD-2); }
    ModInt pow(long long y) const {
	ModInt b = *this, r = 1;
	if (y < 0) { b = b.inv(); y = -y; }
	for (; y; y>>=1) {
	    if (y&1) r *= b;
	    b *= b;
	}
	return r;
    }

    friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
    friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
    friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
    friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
    friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
    friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
    friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};

constexpr LL MOD = 1000000007;
using Mint = ModInt<MOD>;

int N;
int X[200011];
int Y[200011];
LL W[200011];
VI G[200011];

int par[200011];
LL dp[200011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	LL w;
	scanf("%d%d%lld", &x, &y, &w);
	x--;
	y--;
	G[x].push_back(i);
	G[y].push_back(i);
	X[i] = x;
	Y[i] = y;
	W[i] = w;
    }

    VI que;
    que.push_back(0);
    REP (i, N) {
	int v = que[i];
	EACH (e, G[v]) {
	    int w = v ^ X[*e] ^ Y[*e];
	    if (w == par[v]) continue;

	    dp[w] = dp[v] ^ W[*e];
	    par[w] = v;
	    que.push_back(w);
	}
    }

    Mint ans = 0;
    for (int t=60; t--;) {
	LL a = 0;
	REP (i, N) if (dp[i]>>t&1) a++;
	LL b = N - a;


	ans *= 2;
	ans += a * b;
    }

    printf("%d\n", ans.geti());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int N; 
long long mod = 1000000007; 
vector<pair<int, long long>> E[200010]; 
long long A[200010]; 
void dfs(int v, int p){
	int res = 0;
	for(int i = 0; i < (int) E[v].size(); i++){
		int c = E[v][i].first; 
		if(c == p) continue; 
		long long w = E[v][i].second;
		A[c] = (A[v] ^ w); 
		dfs(c, v);  
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N; 
	for(int i = 0; i < N-1; i++){
		int u, v; long long w; 
		cin >> u >> v >> w; 
		u--; v--; 
		E[u].push_back(make_pair(v, w)); 
		E[v].push_back(make_pair(u, w));
	} 
	long long mul = 1LL;
	long long ans = 0;
	dfs(0, -1); 
	for(int d = 0; d < 60; d++){
		long long a = 0; 
		for(int i = 0; i < N; i++){
			if((A[i] >> d) & 1) a ++;
		}
		long long add = a * (N - a) % mod; 
		ans += mul * add % mod; 
		mul *= 2; mul %= mod; 
		ans %= mod; 
	}
	cout << ans << "\n"; 
}