#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<list>
#include<tuple>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct Edge{
    ll to, cost;
    Edge(ll t, ll c) : to(t), cost(c) { }
};
using Graph = vector<vector<Edge>>;

ll MODpow(ll x, ll n, ll mod){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n >>= 1;
	}
	return res;
}

const ll MOD=1e9+7;
const ll nmax=200000+10;

ll N;
Graph G(nmax);

ll calc(ll i){
    ll even=0,odd=0;
    vl res(N,-1),seen(N,0);
    queue<ll> q;
    res[0]=0;
    q.push(0);
    even++;
    
    while(!q.empty()){
        ll v=q.front();
        q.pop();
        seen[v]=1;
        
        for(auto e:G[v]){
            if(seen[e.to]) continue;
            
            bool ec=(e.cost&(1LL<<i));
            q.push(e.to);
            res[e.to]=res[v]^ec;
            if(res[e.to]==1) odd++;
            else even++;
        }
    }
    
    ll mid1=MODpow(2,i,MOD);
    ll mid2=odd*even%MOD;
    ll mid=mid1*mid2%MOD;
    return mid;
}

int main(void){
    cin>>N;
    REP(i,N-1){
        ll u,v,w; cin>>u>>v>>w;
        u--,v--;
        G[u].push_back(Edge{v,w});
        G[v].push_back(Edge{u,w});
    }
    
    ll res=0;
    REP(i,60){
        res+=calc(i);
        res%=MOD;
    }
    cout<<res<<endl;
    
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
const long nPrime = 1000000007;
//const long nPrime = 998244353;
struct Node{
    long iON = 0;
    long iOFF = 1;
};

long DFS(int x, const vector<vector<pair<int,long>>> &vviEdge, 
         vector<Node> &vzNode, vector<int> &viCheck){
    viCheck[x] = 1;
    
    long nReturn = 0;
    for(int i = 0; i < vviEdge[x].size(); i++){
        int y = vviEdge[x][i].first;
        if(viCheck[y] == 1){
            continue;
        }
        nReturn += DFS(y, vviEdge, vzNode, viCheck);
        vzNode[x].iON += (vviEdge[x][i].second == 0) ? vzNode[y].iON 
                                                     : vzNode[y].iOFF;
        vzNode[x].iOFF += (vviEdge[x][i].second == 0) ? vzNode[y].iOFF 
                                                      : vzNode[y].iON;
        vzNode[x].iON %= nPrime;
        vzNode[x].iOFF %= nPrime;
        nReturn -= vzNode[y].iON * vzNode[y].iOFF;
        nReturn %= nPrime;
    }

    nReturn += vzNode[x].iON * vzNode[x].iOFF;
    nReturn %= nPrime;
    return nReturn;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<pair<int,long>>> vviEdge(n);
    for(int i = 0; i < n-1; i++){
        int a,b;
        long c;
        cin >> a >> b >> c;
        vviEdge[a-1].push_back(make_pair(b-1,c));
        vviEdge[b-1].push_back(make_pair(a-1,c));
    }
    
    vector<vector<pair<int,long>>> vviEdgeThis = vviEdge;
    long nAns = 0;
    for(long i = 0; i < 60; i++){
        for(long j = 0; j < n; j++){
            for(long k = 0; k < vviEdgeThis[j].size(); k++){
                vviEdgeThis[j][k].second = ((vviEdge[j][k].second & (1L<<i)) != 0) ? 1:0;
            }
        }
        vector<Node> vzNode(n);
        vector<int> viCheck(n,0);
        long iThis = (1L<<i) % nPrime;
        long nSum = DFS(0, vviEdgeThis, vzNode, viCheck);
        nAns += nSum * iThis;
        nAns %= nPrime;
    }
    
    nAns += nPrime;
    nAns %= nPrime; 
    cout << nAns << endl;
    return 0;
}