#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
struct Gaussian {
  vector<long long> v;
  long long set, rank;
  void push(long long second) {
    if (second) v.push_back(second);
  }
  void clear() { v.clear(); }
  void eliminate() {
    set = rank = 0;
    for (long long bit = 0; bit <= 60; bit++) {
      bool found = false;
      for (long long i = rank; i < v.size(); i++) {
        if (v[i] & (1ll << bit)) {
          swap(v[i], v[rank]);
          found = true;
          break;
        }
      }
      if (found) {
        for (long long i = rank + 1; i < v.size(); i++)
          if (v[i] & (1ll << bit)) v[i] ^= v[rank];
        rank++;
      }
    }
    v.resize(rank);
    for (auto &i : v) set |= i;
  }
} g;
long long vis[100010], vals[100010], cnto[64], cntz[64];
vector<pair<long long, long long> > adj[100010];
void dfs(long long loc) {
  vis[loc] = 1;
  for (long long i = 0; i <= 60; i++)
    if (vals[loc] & (1ll << i))
      cnto[i]++;
    else
      cntz[i]++;
  for (auto &i : adj[loc]) {
    if (!vis[i.first]) {
      vals[i.first] = vals[loc] ^ i.second;
      dfs(i.first);
    } else {
      g.push(vals[i.first] ^ vals[loc] ^ i.second);
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, x, y, z;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      for (long long i = 0; i <= 60; i++) cnto[i] = cntz[i] = 0;
      g.clear();
      dfs(i);
      g.eliminate();
      long long tot = cnto[0] + cntz[0];
      long long nc2 = (tot * (tot - 1) / 2) % mod;
      for (long long i = 0; i <= 60; i++) {
        long long me = (1ll << i) % mod;
        if (g.set & (1ll << i)) {
          me = (me * nc2) % mod;
          long long tmp = (1ll << (g.rank - 1ll)) % mod;
          me = (me * (tmp)) % mod;
        } else {
          me = (me * cnto[i]) % mod;
          me = (me * cntz[i]) % mod;
          long long tmp = (1ll << (g.rank)) % mod;
          me = (me * tmp) % mod;
        }
        ans = (ans + me) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
