#include <bits/stdc++.h>
using namespace std;
struct apple {
  long long v, nxt, q;
} edge[100011 * 8];
long long dist[100011], f[62 + 1], ans, cnt[62 + 1][2], tot, indexx[100011],
    siz, vist[100011], n, m, num[62 + 1][2], used;
long long g[62 + 1];
vector<long long> V;
void addedge(long long x, long long y, long long z) {
  edge[++tot].v = y;
  edge[tot].q = z;
  edge[tot].nxt = indexx[x];
  indexx[x] = tot;
}
void add(long long x) {
  for (long long i = 62; i >= 0; i--) {
    if ((x >> i) & 1) {
      if (f[i])
        x ^= f[i];
      else {
        f[i] = x;
        siz++;
        return;
      }
    }
    if (!x) return;
  }
}
void dfs(long long u, long long fa, long long dep) {
  dist[u] = dep;
  vist[u] = 1;
  long long t = indexx[u], vv, qq;
  V.push_back(u);
  while (t) {
    vv = edge[t].v;
    qq = edge[t].q;
    if (vv != fa) {
      if (!vist[vv])
        dfs(vv, u, dep ^ qq);
      else {
        add(dist[u] ^ dist[vv] ^ qq);
      }
    }
    t = edge[t].nxt;
  }
}
signed main() {
  long long x, y, z;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &x, &y, &z);
    addedge(x, y, z);
    addedge(y, x, z);
  }
  for (long long i = 1; i <= n; i++) {
    if (vist[i]) continue;
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    memset(cnt, 0, sizeof(cnt));
    siz = 0;
    dfs(i, 0, 0);
    for (long long i = 62; i >= 0; i--) {
      for (long long j = 62; j >= 0; j--)
        if ((f[j] >> i) & 1) g[i] = 1;
      long long len = V.size();
      for (long long j = 0; j < len; j++) {
        y = V[j];
        x = ((dist[y] >> i) & 1);
        cnt[i][x]++;
      }
      num[i][0] = (cnt[i][0] * (cnt[i][0] - 1) / 2) % 1000000007 +
                  (cnt[i][1] * (cnt[i][1] - 1) / 2) % 1000000007;
      num[i][0] %= 1000000007;
      num[i][1] = cnt[i][0] * cnt[i][1] % 1000000007;
      if (g[i])
        num[i][0] =
            (num[i][0] * ((1LL << (siz - 1)) % 1000000007)) % 1000000007;
      else
        num[i][0] = 0;
      if (g[i])
        num[i][1] =
            (num[i][1] * ((1LL << (siz - 1)) % 1000000007)) % 1000000007;
      else
        num[i][1] = (num[i][1] * ((1LL << siz) % 1000000007)) % 1000000007;
      ans += (num[i][0] + num[i][1]) * ((1LL << i) % 1000000007) % 1000000007;
      ans %= 1000000007;
    }
    V.clear();
  }
  printf("%lld", ans);
  return 0;
}
