#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

#define endl "\n"
#define INF 0x3f3f3f3f
#define eb emplace_back
#define mem(a, b) memset(a , b , sizeof(a))

// const ll mod = 998244353;
const ll mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);
const double R = 0.57721566490153286060651209;

const int N = 4e5 + 10;

struct Edge {
    int v; ll w;
};

vector<Edge> g[N];
vector<ll> cnt(105), XOR(N);

void dfs(int u, int fa) {
    for(auto e : g[u]) {
        int v = e.v;
        if(v == fa) continue ;
        XOR[v] = XOR[u] ^ e.w;
        dfs(v, u);
    }
    for(int i = 0;i < 65; i++) if(XOR[u] & (1ll << i)) cnt[i + 1]++;
}

void solve() {
    int n; cin >> n;
    for(int i = 1;i < n; i++) {
        int u, v; ll w;
        cin >> u >> v >> w;
        g[u].push_back(Edge{v, w});
        g[v].push_back(Edge{u, w});
    }
    dfs(1, 0);
    ll ans = 0;
    vector<ll> bit(100);
    bit[1] = 1;
    for(int i = 2;i < 65; i++) bit[i] = bit[i - 1] * 2 % mod;
    for(int i = 1;i < 65; i++) {
        ans = (ans + bit[i] * (n - cnt[i]) % mod * cnt[i]) % mod;
    } 
    cout << (ans % mod + mod) % mod << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    // cin.tie(nullptr);
    // cout.tie(nullptr);
#ifdef FZT_ACM_LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    signed test_index_for_debug = 1;
    char acm_local_for_debug = 0;
    do {
        if (acm_local_for_debug == '$') exit(0);
        if (test_index_for_debug > 20)
            throw runtime_error("Check the stdin!!!");
        auto start_clock_for_debug = clock();
        solve();
        auto end_clock_for_debug = clock();
        cout << "Test " << test_index_for_debug << " successful" << endl;
        cerr << "Test " << test_index_for_debug++ << " Run Time: "
             << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
        cout << "--------------------------------------------------" << endl;
    } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
    solve();
#endif
    return 0;
}

#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int main() {
    const long long mod = 1e9+7;

    int N;
    cin >> N;
    vector<vector<long long>> edge(N), weight(N);
    for(int i = 1; i < N; i++) {
        long long u, v, w;
        cin >> u >> v >> w;
        edge[--u].push_back(--v);
        edge[v].push_back(u);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }

    vector<long long> dist(N, -1);
    queue<int> que;
    que.push(0);
    dist[0] = 0;

    while(!que.empty()) {
        int now = que.front();
        que.pop();

        for(int i = 0; i < edge[now].size(); i++) {
            int next = edge[now][i];
            long long sum = dist[now]^weight[now][i];
            if (dist[next] == -1) {
                dist[next] = sum;
                que.push(next);
            }
        }
    }

    long long ans = 0;
    for(int d = 0; d < 60; d++) {
        vector<int> cnt(2);
        for(int k = 0; k < N; k++) cnt[ (dist[k] >> d) & 1 ]++;
//        ans += ((1ll << d) % mod) * ((cnt[0]* cnt[1]) % mod);
        ans += (1ll<<d)%mod*cnt[0]%mod*cnt[1];

        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}