#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXM = 200005;
const int MAXB = 70;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
namespace ModCalculator {
const int MOD = 1e9 + 7;
inline void Inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
inline void Dec(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
inline int Add(int x, int y) {
  Inc(x, y);
  return x;
}
inline int Sub(int x, int y) {
  Dec(x, y);
  return x;
}
inline int Mul(int x, int y) { return 1LL * x * y % MOD; }
inline int ksm(int x, int k) {
  int ret = 1;
  for (; k; k >>= 1) {
    if (k & 1) ret = Mul(ret, x);
    x = Mul(x, x);
  }
  return ret;
}
inline int Inv(int x) { return ksm(x, MOD - 2); }
}  // namespace ModCalculator
using namespace ModCalculator;
int n, m, pw[MAXB];
struct Edge {
  int v, nxt;
  long long w;
} e[MAXM << 1];
int first[MAXN], eCnt;
inline void AddEdge(int u, int v, long long w) {
  e[++eCnt].v = v;
  e[eCnt].w = w;
  e[eCnt].nxt = first[u];
  first[u] = eCnt;
}
int vis[MAXN], siz, occur[MAXB], cnt[MAXB], r;
long long dis[MAXN], base[MAXB];
void Insert(long long x) {
  for (int i = 60; ~i; --i) {
    if ((x >> i) & 1) {
      if (!base[i]) {
        base[i] = x;
        ++r;
        return;
      }
      x ^= base[i];
    }
  }
}
void clean() {
  memset(occur, 0, sizeof(occur));
  memset(cnt, siz = 0, sizeof(cnt));
  memset(base, r = 0, sizeof(base));
}
void DFS(int u, int fa) {
  siz += (vis[u] = 1);
  for (int i = 60; ~i; --i) {
    cnt[i] += ((dis[u] >> i) & 1);
  }
  for (int j = first[u]; j; j = e[j].nxt) {
    int v = e[j].v;
    if (v == fa) continue;
    if (!vis[v]) {
      dis[v] = dis[u] ^ e[j].w;
      DFS(v, u);
    } else {
      long long cir = dis[u] ^ e[j].w ^ dis[v];
      Insert(cir);
      for (int i = 60; ~i; --i) {
        occur[i] |= ((cir >> i) & 1);
      }
    }
  }
}
void init() {
  read(n);
  read(m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    long long w;
    read(u);
    read(v);
    read(w);
    AddEdge(u, v, w);
    AddEdge(v, u, w);
  }
  for (int i = pw[0] = 1; i <= 60; ++i) {
    pw[i] = Add(pw[i - 1], pw[i - 1]);
  }
}
void solve() {
  int ans = 0;
  for (int u = 1; u <= n; ++u) {
    if (vis[u]) continue;
    clean();
    DFS(u, 0);
    for (int i = 60; ~i; --i) {
      if (occur[i]) {
        Inc(ans, Mul((1LL * siz * (siz - 1) / 2) % MOD, Mul(pw[i], pw[r - 1])));
      } else {
        Inc(ans, Mul(Mul(cnt[i], siz - cnt[i]), Mul(pw[i], pw[r])));
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
