#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 7;
const int LOG = (int)65;
const int MOD = (int)1e9 + 7;
const int infint = (int)1e8 + 3;
const long long inf = (long long)1e18;
long long n, m, dp[MAXN], visited[MAXN], cnt[LOG], sz = 0, pwr[LOG],
                                                   inv2 = 500000004;
;
vector<pair<long long, long long> > G[MAXN];
vector<long long> base;
long long bt(long long x, long long i) { return (x >> i) & 1; }
void add(long long x) {
  for (auto u : base)
    if (u & -u & x) x ^= u;
  if (x == 0) return;
  for (int i = 0; i < base.size(); i++)
    if (x & -x & base[i]) base[i] ^= x;
  base.push_back(x);
}
void dfs(int u, int p) {
  sz++;
  for (int j = 0; j < 60; j++)
    if (bt(dp[u], j) == 1) cnt[j]++;
  visited[u] = 1;
  for (auto v : G[u])
    if (!visited[v.first]) {
      dp[v.first] = dp[u] ^ v.second;
      dfs(v.first, u);
    } else if (v.first != p)
      add(dp[u] ^ dp[v.first] ^ v.second);
}
long long C(long long x) {
  long long ans = x * (x - 1 + MOD) % MOD;
  ans = ans * inv2 % MOD;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  pwr[0] = 1;
  for (int i = 1; i < LOG; i++) pwr[i] = (2LL * pwr[i - 1]) % MOD;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visited[i]) continue;
    base.clear();
    memset(cnt, 0, sizeof cnt);
    sz = 0;
    dfs(i, -1);
    for (int j = 0; j < 60; j++) {
      int ted = 0;
      for (auto u : base)
        if (bt(u, j) == 1) ted++;
      if (ted) {
        long long cur = pwr[j] * pwr[base.size() - 1] % MOD;
        long long sm = C(sz);
        ans = (ans + sm * cur % MOD) % MOD;
      } else {
        long long cur = (1LL * cnt[j] * (sz - cnt[j])) % MOD;
        cur = cur * pwr[j] % MOD * pwr[base.size()] % MOD;
        ans = (ans + cur) % MOD;
      }
    }
  }
  cout << ans;
}
