#include <bits/stdc++.h>
using namespace std;
template <typename tp>
void read(tp& dig) {
  char ch = getchar();
  dig = 0;
  long long flag = 0;
  while (!isdigit(ch)) {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (isdigit(ch)) dig = dig * 10 + ch - '0', ch = getchar();
  if (flag) dig = -dig;
}
long long n, m, ans, sum, tot, lnum, p[70], dis[100010], vis[100010];
long long fst[100010], nxt[400010], to[400010], val[400010];
long long cnt[2], pot[100010], lop[400010 << 1];
inline void add_edge(long long u, long long v, long long value) {
  nxt[++lnum] = fst[u];
  fst[u] = lnum;
  to[lnum] = v;
  val[lnum] = value;
  nxt[++lnum] = fst[v];
  fst[v] = lnum;
  to[lnum] = u;
  val[lnum] = value;
}
inline void dfs(long long u, long long fa) {
  vis[u] = 1;
  for (long long i = fst[u]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    if (!vis[to[i]]) {
      dis[to[i]] = dis[u] ^ val[i];
      dfs(to[i], u);
      pot[++pot[0]] = to[i];
    } else
      lop[++tot] = dis[to[i]] ^ dis[u] ^ val[i];
  }
}
inline void inst(long long x) {
  for (long long i = 60; i >= 0; --i) {
    if (!(x & (1LL << i))) continue;
    if (!p[i]) {
      p[i] = x;
      break;
    } else
      x ^= p[i];
  }
}
inline void calc() {
  for (long long i = 0, flag, tmp; i <= 60; ++i) {
    cnt[0] = cnt[1] = 0;
    flag = 0;
    for (long long j = 1; j <= pot[0]; ++j) ++cnt[(dis[pot[j]] >> i) & 1];
    for (long long j = 0; j <= 60; ++j)
      if ((p[j] >> i) & 1) {
        flag = 1;
        break;
      }
    if (flag) {
      tmp = (cnt[0] * (cnt[0] - 1) / 2 % 1000000007 +
             cnt[1] * (cnt[1] - 1) / 2 % 1000000007) %
            1000000007;
      if (sum) {
        tmp = tmp * ((1LL << sum - 1) % 1000000007) % 1000000007;
        ans = (ans + tmp * ((1LL << i) % 1000000007) % 1000000007) % 1000000007;
      }
    }
    tmp = cnt[0] * cnt[1] % 1000000007;
    if (flag) {
      if (sum) tmp = tmp * ((1LL << sum - 1) % 1000000007) % 1000000007;
    } else
      tmp = tmp * ((1LL << sum) % 1000000007) % 1000000007;
    ans = (ans + tmp * ((1LL << i) % 1000000007) % 1000000007) % 1000000007;
  }
}
int main() {
  read(n);
  read(m);
  long long x, y, z;
  for (long long i = 1; i <= m; ++i) {
    read(x);
    read(y);
    read(z);
    add_edge(x, y, z);
  }
  for (long long i = 1; i <= n; ++i) {
    if (vis[i]) continue;
    for (long long j = 1; j <= pot[0]; ++j) pot[j] = 0;
    sum = pot[0] = 0;
    memset(p, 0, sizeof p);
    tot = 0;
    pot[++pot[0]] = i;
    dfs(i, 0);
    for (long long j = 1; j <= tot; ++j) inst(lop[j]);
    for (long long j = 0; j <= 60; ++j)
      if (p[j]) ++sum;
    calc();
  }
  printf("%lld\n", ans);
  return 0;
}
