#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, L = 61, B = 1e9 + 7;
vector<pair<int, long long> > e[N];
int ret, vis[N], n, m, u, v;
long long dep[N], w, pw[L * 4];
struct guass {
  int cnt[L + 10][2], rk;
  long long cyc[L + 10], s;
  void init() {
    for (int i = 0; i < L; ++i) cyc[i] = cnt[i][0] = cnt[i][1] = 0;
    rk = 0, s = 0;
  }
  void dda(long long w) {
    for (int i = 0; i < L; ++i) cnt[i][(w >> i) & 1]++;
  }
  void add(long long w) {
    s |= w;
    for (int i = L - 1; i >= 0; --i) {
      if (w & (1ll << i)) {
        if (cyc[i] == 0) {
          cyc[i] = w, rk++;
          break;
        }
      }
      w = min(w, w ^ cyc[i]);
    }
  }
  void count() {
    for (int i = 0; i < L; ++i) {
      if (s & (1ll << i)) {
        ret = (ret + (long long)(cnt[i][0] + cnt[i][1]) *
                         (cnt[i][0] + cnt[i][1] - 1) / 2 % B * pw[i + rk - 1]) %
              B;
      } else {
        ret = (ret + (long long)cnt[i][0] * cnt[i][1] % B * pw[i + rk]) % B;
      }
    }
  }
} base;
void dfs(int u, int f, long long w) {
  vis[u] = 1;
  dep[u] = w;
  base.dda(w);
  for (auto p : e[u]) {
    int v = p.first;
    if (v == f) continue;
    if (vis[v]) {
      base.add(dep[u] ^ dep[v] ^ p.second);
      continue;
    }
    dfs(v, u, w ^ p.second);
  }
}
void initpw() {
  pw[0] = 1;
  for (int i = 1; i < L * 4; ++i) pw[i] = (pw[i - 1] << 1) % B;
}
int main() {
  initpw();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%lld", &u, &v, &w);
    e[u].push_back(make_pair(v, w));
    e[v].push_back(make_pair(u, w));
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      base.init();
      dfs(i, 0, 0);
      base.count();
    }
  printf("%d\n", ret);
  return 0;
}
