#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,l,r) for(int i=int(l);i<=int(r);i++)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i, j, n, pref[N];
vpii g[N];

void dfs(int v, int par) {
    for (auto &p : g[v]) {
        int u = p.f, w = p.s;
        if (u != par) {
            pref[u] = pref[v] ^ w;
            dfs(u, v);
        }
    }
}

void burn() {
    cin >> n;
    for (i = 1; i <= n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].pb({v, w});
        g[v].pb({u, w});
    }
    pref[1] = 0;
    dfs(1, 0);
    int ans = 0;
    for (j = 0; j < 62; j++) {
        int odd = 0, even = 0;
        for (i = 1; i <= n; i++) {
            if (pref[i] >> j & 1) {
                odd++;
            } else {
                even++;
            }
        }
        int pairs = (odd * even) % mod, contri = (1LL << j) % mod;
        ans += (pairs * contri) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
    int t = 1;
    // cin >> t;
    while (t--) {
        burn();
    }
    return 0;
}
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <numeric>
#include <chrono>
#include <random>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstring>
#include <cassert>
#include <climits>
#include <complex>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod =998244353;

int dp[N][2], arr[N], n;

int solve(int i, bool j) {
    if(i == n) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int ret = 0;

    if(!j) {
        ret = solve(i + 1, 0);
        if(i != n - 1) ret = (ret + 1ll * arr[i] * solve(i + 1, 1) % mod) % mod;
        ret = (ret + 1ll * arr[i] * arr[i] % mod) % mod;
    }
    else {
        ret = arr[i];
        if(i != n - 1) ret = (ret + 2ll * solve(i + 1, j) % mod) % mod;
    }

    return dp[i][j] = ret;
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    for(int cn = 1; cn <= tc; cn++) {
         scanf("%d", &n);
        for(int i = 0; i < n; i++)
            scanf("%d", &arr[i]);

        sort(arr, arr + n);
        memset(dp, -1, sizeof(dp));
        printf("%d\n", solve(0, 0));
    }
    return 0;
}
