//#include <bits/stdc++.h>
//using namespace std;
#include <cstdio>
#include <vector>
using namespace std;

#define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i)
#define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i)
#define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
#define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
#define print(x,y) write(x),putchar(y)
//#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0)
//template <typename T> void Out(T x) {cerr<<x<<"\n";}
//template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);}

template <class T> inline T read(const T sample) {
    T x=0; int f=1; char s;
    while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
    while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
    return x*f;
}
template <class T> inline void write(const T x) {
    if(x<0) return (void) (putchar('-'),write(-x));
    if(x>9) write(x/10);
    putchar(x%10^48);
}
template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
template <class T> inline T fab(const T x) {return x>0?x:-x;}
template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;}
template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;}
template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}

typedef long long ll;
typedef pair <int,ll> Pair;

const int maxn=2e5+5,mod=1e9+7;

int n,ans;
ll dep[maxn];
vector <Pair> g[maxn]; 

void dfs(int u,int fa) {
	for(int i=0;i<g[u].size();++i) {
		int v=g[u][i].first;
		if(v==fa) continue;
		dep[v]=(dep[u]^g[u][i].second);
		dfs(v,u);
	}
}

int main() {
	n=read(9);
	rep(i,1,n-1) {
		int u=read(9),v=read(9); ll w=read(9ll);
		g[u].push_back(make_pair(v,w)),g[v].push_back(make_pair(u,w));
	}
	dfs(1,0);
	rep(i,0,60) {
		int cnt=0;
		rep(j,1,n) if(dep[j]>>i&1) ++cnt;
		ans=(ans+1ll*(1ll<<i)%mod*cnt%mod*(n-cnt)%mod)%mod;
	}
	print(ans,'\n');
	return 0;
}
 
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 100000000000000000LL
#define ll  long long 
#define debug(x) cout << #x << " "<< x <<endl; 
#define debug_vector(v) cout << #v << " "; _print(v);
const ll inf =1e9+44;
const int MAX=3e5+9;
const ll MOD= 1e9+7;
const double eps=1e-10;
double const PI=3.1415926535897931;
using namespace std;
int dx[4] = {1 ,0 , - 1, 0};
int dy[4] = {0 ,1 ,  0 , -1};
void _print(vector<int> v){
	cout << "[ ";
	for ( auto u : v)
		cout << u << " ";
	cout << " ]"<< endl;
}
ll x[MAX];
vector < pair<int , ll >  >adj[MAX];
ll arr[MAX];
void dfs(int u , int  p ){

	for(auto v : adj[u]){
		if(v.first == p)
			continue;
		x[v.first] = x[u]^v.second;
		dfs(v.first , u);
	}
}
int main(){
	int n;
	cin >> n;
	for(int i = 0 ; i <n-1 ;i++){
		int x, y;
		ll w;
		cin >> x >> y >> w;
		adj[x].push_back(  { y , w});
		adj[y].push_back( { x, w });
	}
	dfs( 1 , 0 );

	ll ans = 0;
	for ( ll j = 0 ; j <=60 ; j++){
		ll o = 0 , z = 0;
		for (int i = 1 ; i <= n ; i++){
			 if (x[i]&(1ll<<j))
			 	o ++;
			 else
			 	z ++;
			// cout << x[i] << endl;
		}
		//cout << z <<" " <<o << endl;
		 z  = (z*o+MOD)%MOD;
		 ans = ans  + (1ll<<j)%MOD*z%MOD+MOD;
		 ans = ans%MOD;
	}
	cout << ans;

}
 