#include <bits/stdc++.h>
using namespace std;
const long long MAX = 4e5 + 7;
const long long MOD = 1e9 + 7;
void print(bool a) { cout << (a ? "YES" : "NO") << '\n'; }
long long N, M;
struct edge {
  long long next, to;
  long long val;
} e[MAX << 1];
long long head[MAX], eid = 1;
void adde(long long x, long long y, long long w) {
  e[++eid].next = head[x];
  e[eid].to = y;
  e[eid].val = w;
  head[x] = eid;
}
long long tot = 0;
long long vis[MAX];
long long P[67];
void insert(long long x) {
  for (long long i = 62; i >= 0; i--) {
    if (x >> i & 1LL) {
      if (!P[i]) {
        tot++;
        P[i] = x;
        break;
      } else {
        x ^= P[i];
      }
    }
  }
}
long long siz = 0;
long long fir[MAX];
long long A[MAX];
void dfs(long long u, long long now) {
  A[++siz] = u;
  fir[u] = now;
  vis[u] = 1;
  for (long long i = head[u]; i; i = e[i].next) {
    long long v = e[i].to;
    if (!vis[v]) {
      dfs(v, now ^ e[i].val);
    } else {
      insert(now ^ e[i].val ^ fir[v]);
    }
  }
}
long long quick_pow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1LL) ret = ret * x % MOD;
    y >>= 1LL;
    x = x * x % MOD;
  }
  return ret;
}
signed main() {
  cin >> N >> M;
  for (long long i = 1; i <= M; i++) {
    long long x, y, w;
    cin >> x >> y >> w;
    adde(x, y, w);
    adde(y, x, w);
  }
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    if (!vis[i]) {
      siz = 0;
      tot = 0;
      memset(P, 0, sizeof(P));
      dfs(i, 0);
      for (long long j = 0; j <= 62; j++) {
        bool ok = 0;
        for (long long k = 0; k <= 62; k++) {
          if (P[k] >> j & 1LL) {
            ok = 1;
          }
        }
        if (ok) {
          ans = (ans + (siz * (siz - 1LL) / 2LL) % MOD *
                           ((1LL << tot - 1) % MOD) % MOD * ((1LL << j) % MOD) %
                           MOD) %
                MOD;
        } else {
          long long X = 0;
          for (long long k = 1; k <= siz; k++) {
            if (fir[A[k]] >> j & 1LL) {
              X++;
            }
          }
          ans = (ans + (X) * (siz - X) % MOD * ((1LL << j) % MOD) % MOD *
                           ((1LL << tot) % MOD) % MOD) %
                MOD;
        }
      }
    }
  }
  cout << ans % MOD << '\n';
}
