#include <bits/stdc++.h>
const unsigned P = 1000000007;
inline unsigned long long moc(unsigned long long a) {
  return a < P ? a : a - P;
}
inline unsigned long long mod(unsigned long long a) {
  return a < P ? a : a % P;
}
struct edg {
  int v;
  unsigned long long w;
  bool t;
  edg *e, *f;
} ES[200000 * 2], *ER = ES, *EA[100000 + 1];
inline void edg_ins(int u, int v, unsigned long long w) {
  *ER = (edg){v, w, false, EA[u], ER + 1}, EA[u] = ER++;
  *ER = (edg){u, w, false, EA[v], ER - 1}, EA[v] = ER++;
}
int R;
unsigned long long L, d[100000 + 1], a[60][2], b[60], c[60 + 1], w, s, t, ans;
bool vis[100000 + 1];
inline void ins(unsigned long long x) {
  for (register int i = 0; i < R; ++i)
    if (!(x >> i & 1))
      continue;
    else if (b[i])
      x ^= b[i];
    else {
      b[i] = x;
      break;
    }
}
inline void dfs(int u) {
  vis[u] = true;
  for (register int i = 0; i < R; ++i) ++a[i][d[u] >> i & 1];
  for (register edg* e = EA[u]; e; e = e->e)
    if (!vis[e->v])
      d[e->v] = d[u] ^ e->w, e->t = e->f->t = true, dfs(e->v);
    else if (!e->t)
      ins(d[u] ^ d[e->v] ^ e->w), e->t = e->f->t = true;
}
struct buf {
  template <typename _nt>
  operator _nt() {
    register int c = getchar();
    register _nt x = 0;
    for (; !isdigit(c); c = getchar())
      ;
    for (; isdigit(c); c = getchar()) x = x * 10 - '0' + c;
    return x;
  }
} fio;
int V, E, u, v, i, r;
int main() {
  V = fio, E = fio;
  while (E--) u = fio, v = fio, w = fio, edg_ins(u, v, w), L = std::max(L, w);
  for (R = 0; (1ULL << R) <= L; ++R)
    ;
  c[0] = 1;
  for (i = 1; i <= R; ++i) c[i] = moc(c[i - 1] << 1);
  for (u = 1; u <= V; ++u)
    if (!vis[u]) {
      dfs(u);
      r = 0;
      for (i = 0; i < R; ++i)
        if (b[i]) ++r, b[0] |= b[i];
      w = mod((a[0][0] + a[0][1]) * (a[0][0] + a[0][1] - 1) / 2);
      if (r) w = mod(w * c[r - 1]);
      s = t = 0;
      for (i = 0; i < R; ++i)
        if (b[0] >> i & 1)
          s = moc(s + c[i]);
        else
          t = mod(t + c[i] * mod(a[i][0] * a[i][1]));
      ans = mod(ans + s * w + t * c[r]);
      for (i = 0; i < R; ++i) a[i][0] = a[i][1] = 0, b[i] = 0;
    }
  printf("%u\n", unsigned(ans));
  return 0;
}
