#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
long long c;
long long p[66];
void insert(long long x) {
  for (long long i = 59; i >= 0; i--)
    if (x >> i & 1)
      if (!p[i]) {
        p[i] = x;
        ++c;
        break;
      } else
        x ^= p[i];
}
struct node {
  long long to, next, v;
} w[1000005];
long long h[1000005], cnt;
void add(long long x, long long y, long long v) {
  ++cnt;
  w[cnt].to = y;
  w[cnt].next = h[x];
  w[cnt].v = v;
  h[x] = cnt;
}
long long dis[1000005], q[1000005], tot, d[1000005];
bool vis[1000005];
void dfs(long long x, long long fa) {
  vis[x] = 1;
  q[++tot] = d[x];
  for (long long i = h[x]; i; i = w[i].next) {
    long long y = w[i].to;
    if (y == fa) continue;
    if (!vis[y])
      d[y] = d[x] ^ w[i].v, dfs(y, x);
    else
      insert(d[x] ^ d[y] ^ w[i].v);
  }
}
const long long mod = 1e9 + 7;
long long C(long long x) { return 1ll * x * (x - 1) / 2 % mod; }
int main() {
  long long n = read(), m = read();
  for (long long i = 1; i <= m; i++) {
    long long x = read(), y = read(), v = read();
    add(x, y, v);
    add(y, x, v);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) {
      c = tot = 0;
      memset(p, 0, sizeof(p));
      dfs(i, 0);
      long long x = 0;
      for (long long j = 0; j <= 59; j++) x |= p[j];
      for (long long j = 0; j <= 59; j++)
        if (x >> j & 1)
          ans =
              (ans + (1ll << j) % mod * ((1ll << c - 1) % mod) % mod * C(tot)) %
              mod;
        else {
          long long all = 0;
          for (long long k = 1; k <= tot; k++)
            if (q[k] >> j & 1) ++all;
          ans = (ans + (1ll << j) % mod * (tot - all) % mod * all % mod *
                           ((1ll << c) % mod)) %
                mod;
        }
    }
  cout << ans << '\n';
  return 0;
}
