#include <bits/stdc++.h>
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int p = 1e9 + 7;
int c[60][2], r[N];
long long l[60], d[N], t;
void ins(long long j) {
  for (int i = 59; ~i; --i)
    if (j >> i & 1)
      if (l[i])
        j ^= l[i];
      else {
        l[i] = j;
        break;
      }
}
long long val(long long n) { return n * (n - 1) / 2; }
void sol() {
  long long j = 0, v = 1, s = 0;
  for (int i = 59; ~i; --i) {
    j |= l[i];
    v <<= !!l[i];
  }
  for (int i = 59; ~i; --i) {
    s = (j >> i & 1) * v / 2 % p;
    (t +=
     ((val(c[i][0]) + val(c[i][1])) * s + (v - s) % p * c[i][0] * c[i][1]) % p *
     ((1ll << i) % p)) %= p;
  }
}
struct edge {
  int v;
  long long w;
  edge* s;
} e[M * 2];
edge *back = e, *h[N];
void add(int u, int v, long long w) {
  edge s = {v, w, h[u]};
  edge t = {u, w, h[v]};
  *(h[u] = back++) = s;
  *(h[v] = back++) = t;
}
void dfs(int u) {
  for (int i = 59; ~i; --i) ++c[i][d[u] >> i & 1];
  r[u] = 1;
  for (edge* i = h[u]; i; i = i->s)
    if (!r[i->v]) {
      d[i->v] = d[u] ^ i->w;
      dfs(i->v);
    } else
      ins(d[u] ^ d[i->v] ^ i->w);
}
int main() {
  int n, m, x, y;
  long long z;
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d%I64d", &x, &y, &z);
    add(x, y, z);
  }
  for (int i = 1; i <= n; ++i)
    if (!r[i]) {
      memset(c, 0, sizeof c);
      memset(l, 0, sizeof l);
      dfs(i), sol();
    }
  printf("%I64d\n", t);
}
