// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                           CSE - 2019-2023                                     *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loope(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloope(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define vii vector<vector<int>>
#define si set<int>
#define NO cout<<"NO\n";
#define YES cout<<"YES\n";
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);

//modular arithmentic
ll m = 1e9 + 7;
// ll m = 998244353;

ll add(ll a, ll b, ll mod = m)
{
    return ((a % mod) + (b % mod)) % mod;
}
ll mul(ll a, ll b, ll mod = m)
{
    return ((a % mod) * (b % mod)) % mod;
}
ll sub(ll a, ll b, ll mod = m)
{
    return ((a % mod) - (b % mod) + mod) % mod;
}

template <typename T>
void dis(vector<T> &vec)
{
    for (const auto &v : vec)
    {
        cout << v << " ";
    }
    cout << "\n";
}
template <typename T1, typename T2>
void disp(vector<pair<T1, T2>> &vec)
{
    for (const auto &v : vec)
    {
        cout << v.ff << " " << v.ss << "\n";
    }
    cout << "\n";
}

//graph theory
vector<pair<int, ll>> adj[200005];

int mx = 60;
void solve()
{
    int n; cin >> n;
    loop(i, 0, n - 1)
    {
        int a, b; ll c;
        cin >> a >> b >> c;
        adj[a].pb(MP(b, c));
        adj[b].pb(MP(a, c));
    }
    queue<int>vals;
    vector<ll> vis(n + 1), xo(n + 1);
    vals.push(1);
    ll ans = 0;
    vis[1] = 1;

    while (vals.size())
    {
        int top = vals.front(); vals.pop();
        for (const auto &v : adj[top])
        {
            if (vis[v.ff])continue;
            vis[v.ff] = 1;
            vals.push(v.ff);
            xo[v.ff] = xo[top] ^ v.ss;
        }
    }

    loop(i, 0, mx)
    {
        int vals[2] = {0};
        loope(j, 1, n)vals[(xo[j] >> i) & 1]++;
        // loope(j, 1, n)cout << ((xo[j] >> i) & 1) << " ";

        // cout << "\n";
        ans = add(ans, mul(vals[0], mul(vals[1], 1ll << i)));

        // cout << vals[0] << " " << vals[1] << " " << (1ll << i) << " " << ans << "\n";
    }
    cout << ans << "\n";
}

int main()
{
    io;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test = 1, i = 0;
    // cin >> test;
    while (i++ != test)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inv2 = 5e8 + 4;

int n, cntall[65][2], cntlocal[65][2];
int dp[N];
bool visited[N];
int ans = 0, res = 0;
vector <pair <long long, int> > g[N];

void add(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

void sub(int &x, int y) {
    x -= y;
    if (x < 0) x += mod;
}

void dfs(int u, int p) {
    dp[u] = 1;
    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (v == p || visited[v]) continue;
        dfs(v, u);
        dp[u] += dp[v];
    }
}

int findcen(int u, int p, int sz) {
    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (v != p && !visited[v] && dp[v] > sz / 2) {
            return findcen(v, u, sz);
        }
    }

    return u;
}

void predfs(int u, int p, long long w) {
    for (int i = 60; i >= 0; i--) {
        cntall[i][(w >> i) & 1]++;
    }

    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (v != p && !visited[v]) {
            predfs(v, u, w ^ g[u][i].first);
        }
    }
}

void localdfs(int u, int p, long long w) {
    for (int i = 60; i >= 0; i--) {
        cntlocal[i][(w >> i) & 1]++;
    }

    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (v != p && !visited[v]) {
            localdfs(v, u, w ^ g[u][i].first);
        }
    }
}

void calc(int u, int p, long long w) {
    //cout << u << " " << p << " " << w << "\n";
    add(res, w % mod);
    for (int i = 60; i >= 0; i--) {
        add(ans, (1LL << i) % mod * cntall[i][((w >> i) & 1) ^ 1] % mod);
        sub(ans, (1LL << i) % mod * cntlocal[i][((w >> i) & 1) ^ 1] % mod);
    }

    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (v != p && !visited[v]) {
            calc(v, u, w ^ g[u][i].first);
        }
    }
}

void centroid(int u) {
    dfs(u, u); u = findcen(u, u, dp[u]);
    visited[u] = true; memset(cntall, 0, sizeof(cntall));

    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (visited[v]) continue;
        predfs(v, u, g[u][i].first);
    }

    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (visited[v]) continue;
        memset(cntlocal, 0, sizeof(cntlocal));
        localdfs(v, u, g[u][i].first);
        calc(v, u, g[u][i].first);
    }

    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i].second;
        if (!visited[v]) centroid(v);
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        long long w;
        cin >> u >> v >> w;
        g[u].push_back(make_pair(w, v));
        g[v].push_back(make_pair(w, u));
    }

    centroid(1);
    ans = 1LL * ans * inv2 % mod;
    add(ans, res);
    cout << ans << "\n";
    return 0;
}
/*
3
1 2 1
1 3 3
*/
