// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

#define int long long int

#define vi vector<int>
 
#define ff first
#define ss second
 
#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
#define Graph vector<vi>
#define Graphw vector<vector<pair<int,int>>> 
#define sz(x) (int)x.size()
#define pr pair<int,int>
 
#define display(v) for(int i =0;i<(int)v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
#define read(a) for(int i = 0;i<(int)a.size();++i)cin>>a[i]
#define show(x) cout << #x << " is " << x << "\n";
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_si;
// typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_msi;
#define show_arr(a) cout << #a << "\n"; display(a) ; cout << "\n";
inline int add(int a, int b){ int c = (a%MOD) + (b%MOD); if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return ((a%MOD) * 1ll * (b%MOD)) % MOD; }
inline int sub(int a, int b){ int c = (a%MOD) - (b%MOD); if(c < 0) c += MOD; return c; }
inline int sum_till(int n) { return mul(mul(n, n + 1), (MOD + 1) / 2); }
const int nax = 300*1000 + 10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#define ook order_of_key
//#define fbo find_by_order
//   order_of_key(x) -> number of elements less than x.
// * find_by_order(x) -> gives the element at index x (0 - indexing)

void test_case();
int32_t main()
{
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    int t = 1; //cin>>t;
    while(t--){
        test_case();
    }
    return 0;
}

int sumXOR(vi arr)
{
    int sum = 0;
    for (int i = 0; i < 61; i++) 
    {
        //  Count of zeros and ones
        int zc = 0, oc = 0; 
          
        // Individual sum at each bit position
        int idsum = 0; 
        for (int j = 0; j < sz(arr); j++)
        {
            if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;
        }
          
        // calculating individual bit sum 
        idsum = mul(oc , mul(zc , (1LL<<i)));
  
        // final sum    
        sum  = add(sum , idsum); 
    }
    return sum;
}

int n;
Graphw G;
vi val;

void dfs(int st , int par = -1 , int cur = 0LL){
    val[st] = cur;
    //cout << st << '\n';
    for(pr to : G[st]){
        if(to.ff != par){
            dfs(to.ff , st , cur^to.ss);
        }
    }
}

void test_case(){
    cin>>n;
    val = vi(n + 1 , 0);
     G = Graphw(n + 1);
    for(int i = 0;i < n - 1 ; ++i){
        int u   ,v , w; cin>>u>>v>>w;
        G[u].pb({v , w});
        G[v].pb({u , w});
    }
    //cout << "Hi";
    dfs(1);
    vi arr;
    for(int i = 1; i <= n ; ++i){
        arr.pb(val[i]);
    }
    cout << sumXOR(arr);
}    

// Химаншу
// check overflow
// special case n == 1
// 🍪🍪🍪

	
// Code Created BY LEO_VALDEZ
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x).size()
#define sarr(x) (int)(sizeof(x)/sizeof(x[0]))
#define mp make_pair
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define p2(x) (1ll<<x)
#define pob pop_back
#define f first
#define s second
#define in pair<int, int>
#define INF 1000000000000000
#define MX (int)2e5+5
const int mod = 1e9 + 7;// make this 98953... if reqd
vector<in> Adj[MX];
int dp[MX];
void DFS(int u, int p, int val)
{
	dp[u] = val;
	for(in vw : Adj[u])
	{
		int v = vw.f;
		int w = vw.s;
		if(v==p)
			continue;
		DFS(v, u, val^w);
	}
	return;
}
signed main()
{
	int n;
	cin >> n;
	int m = n-1;
	while(m--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		Adj[a].pb({b, c});
		Adj[b].pb({a, c});
	}
	DFS(0, -1, 0);
	vector<int> a(60, 0);
	vector<int> b(60, 0);
	for(int i = 0; i < 60; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if((dp[j]>>i)&1)
				a[i]++;
			else
				b[i]++;
		}
	}
	int ans = 0;
	for(int i = 0; i < 60; i++)
	{
		int po = (1ll<<i)%mod;
		int other = (a[i]*b[i])%mod;
		ans+=((po*other)%mod);
		ans%=mod;
	}
	cout << ans << endl;
	return 0;
}