#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const int N = 2e5 + 1, K = 61, MOD = 1e9 + 7;
int n, m;
ll ans, pw[2 * K], d[N], cnt[K][2], f[K];
vector<ll> paths, cycles;
vector<pair<int, ll> > g[N];
bool mark[N];
void dfs(int u, int par) {
  mark[u] = true;
  paths.push_back(d[u]);
  for (auto p : g[u]) {
    int v;
    ll w;
    tie(v, w) = p;
    if (v == par) continue;
    if (mark[v])
      cycles.push_back(d[u] ^ d[v] ^ w);
    else {
      d[v] = d[u] ^ w;
      dfs(v, u);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0, u, v; i < m; i++) {
    ll w;
    cin >> u >> v >> w;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }
  pw[0] = 1;
  for (int i = 1; i < 2 * K; i++) pw[i] = pw[i - 1] * 2 % MOD;
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      paths.clear();
      cycles.clear();
      memset(cnt, 0, sizeof(cnt));
      memset(f, 0, sizeof(f));
      dfs(i, 0);
      for (ll x : paths) {
        for (int j = K - 1; j >= 0; j--) ++cnt[j][x >> j & 1];
      }
      ll cycle_space = 0;
      int dimension = 0;
      for (ll x : cycles) {
        cycle_space |= x;
        for (int j = K - 1; j >= 0; j--)
          if (x >> j & 1) {
            if (!f[j]) {
              f[j] = x;
              ++dimension;
              break;
            }
            x ^= f[j];
          }
      }
      ll res = 0;
      for (int j = K - 1; j >= 0; j--) {
        if (cycle_space >> j & 1)
          res += (cnt[j][0] + cnt[j][1]) * (cnt[j][0] + cnt[j][1] - 1) / 2 %
                 MOD * pw[j + dimension - 1] % MOD;
        else
          res += pw[j + dimension] * cnt[j][0] % MOD * cnt[j][1] % MOD;
        res %= MOD;
      }
      ans = (ans + res) % MOD;
    }
  cout << ans;
}
