#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int mod = 1000000007;
const int MAXN = 200011;
const int MAXM = 400011;
int n, m, ecnt, first[MAXN], to[MAXM], nxt[MAXM], scnt, dfn[MAXN], cir_cnt, r;
long long dis[MAXN], w[MAXM], p[70], cir[MAXM], ans, poww[MAXM << 1], cnt[2];
bool vis[MAXN], in[MAXN];
inline void link(int x, int y, long long z) {
  nxt[++ecnt] = first[x];
  first[x] = ecnt;
  to[ecnt] = y;
  w[ecnt] = z;
}
inline int getint() {
  int w = 0, q = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 1, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? -w : w;
}
inline long long getlong() {
  long long w = 0, q = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 1, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? -w : w;
}
void dfs(int x, long long d, int fa) {
  if (dis[x] == -1)
    dis[x] = d;
  else {
    cir[++cir_cnt] = d ^ dis[x];
    return;
  }
  vis[x] = 1;
  dfn[++scnt] = x;
  for (int i = first[x]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    dfs(to[i], d ^ w[i], x);
  }
}
inline void build() {
  memset(p, 0, sizeof p);
  r = 0;
  for (int i = 1; i <= cir_cnt; i++) {
    for (int j = 62; j + 1; j--) {
      if (!(cir[i] >> j) & 1) continue;
      if (!p[j]) {
        p[j] = cir[i];
        break;
      }
      cir[i] ^= p[j];
    }
  }
  for (int j = 0; j <= 62; j++)
    if (p[j]) r++;
}
inline long long calc() {
  build();
  long long tot = 0;
  for (int i = 0; i <= 62; i++) {
    cnt[0] = cnt[1] = 0;
    bool flag = 0;
    for (int j = 0; j <= 62; j++)
      if ((p[j] >> i) & 1) {
        flag = 1;
        break;
      }
    for (int j = 1; j <= scnt; j++) cnt[(dis[dfn[j]] >> i) & 1]++;
    long long now =
        (cnt[0] * (cnt[0] - 1) / 2 + cnt[1] * (cnt[1] - 1) / 2) % mod;
    if (flag) {
      if (r) now *= poww[r - 1], now %= mod;
      now *= poww[i], now %= mod;
      tot += now, tot %= mod;
    }
    now = cnt[0] * cnt[1], now %= mod;
    if (flag && r)
      now *= poww[r - 1], now %= mod;
    else if (!flag)
      now *= poww[r], now %= mod;
    now *= poww[i], now %= mod;
    tot += now;
    tot %= mod;
  }
  return tot;
}
inline void work() {
  n = getint();
  m = getint();
  int x, y, lim = max(n, m) * 2;
  long long z;
  for (int i = 1; i <= m; i++) {
    x = getint();
    y = getint();
    z = getlong();
    link(x, y, z);
    link(y, x, z);
  }
  poww[0] = 1;
  for (int i = 1; i <= lim; i++) poww[i] = poww[i - 1] * 2, poww[i] %= mod;
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    scnt = 0;
    cir_cnt = 0;
    dfs(i, 0, 0);
    ans += calc();
    ans %= mod;
  }
  printf("%I64d", ans);
}
int main() {
  work();
  return 0;
}
