#include <bits/stdc++.h>
using namespace std;
const int maxn = 400040, mod = 1000000007;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 0;
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, m, el, head[maxn], to[maxn], nxt[maxn], ans, rk, fa[maxn], tu[maxn],
    tv[maxn], tl, cnt[60][2], tot, p[maxn];
long long w[maxn], lb[60], dis[maxn], tw[maxn];
bool vis[maxn], in[60];
inline void add(int u, int v, long long w_) {
  to[++el] = v;
  nxt[el] = head[u];
  head[u] = el;
  w[el] = w_;
}
void insert(long long x) {
  for (int i = (59); i >= (0); i--)
    if ((x >> i) & 1) {
      if (!lb[i]) {
        lb[i] = x;
        rk++;
        for (int j = (0); j <= (59); j++)
          if ((x >> j) & 1) in[j] = true;
        break;
      }
      x ^= lb[i];
    }
}
void dfs(int u) {
  vis[u] = true;
  p[++tot] = u;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa[u]) continue;
    if (vis[v]) {
      tu[++tl] = u;
      tv[tl] = v;
      tw[tl] = w[i];
      continue;
    }
    dis[v] = dis[u] ^ w[i];
    fa[v] = u;
    dfs(v);
  }
}
void solve(int u) {
  dfs(u);
  for (int i = (1); i <= (tl); i++) insert(dis[tu[i]] ^ dis[tv[i]] ^ tw[i]);
  for (int i = (0); i <= (59); i++) {
    int sum = 0;
    for (int j = (1); j <= (tot); j++)
      if ((dis[p[j]] >> i) & 1) sum++;
    cnt[i][1] = (1ll * sum * (tot - sum)) % mod;
    cnt[i][0] = (1ll * tot * (tot - 1) / 2 - cnt[i][1]) % mod;
  }
  int x = (1ll << rk) % mod;
  for (int i = (0); i <= (59); i++)
    if (in[i]) {
      int y = (1ll << (rk - 1)) % mod;
      ans = (ans + (1ll << i) % mod * y % mod * (cnt[i][0] + cnt[i][1])) % mod;
    } else
      ans = (ans + (1ll << i) % mod * x % mod * cnt[i][1]) % mod;
  for (int i = (0); i <= (59); i++) cnt[i][0] = cnt[i][1] = lb[i] = in[i] = 0;
  tl = tot = rk = 0;
}
int main() {
  n = read();
  m = read();
  for (int i = (1); i <= (m); i++) {
    int u = read(), v = read();
    long long w = read();
    add(u, v, w);
    add(v, u, w);
  }
  for (int i = (1); i <= (n); i++)
    if (!vis[i]) solve(i);
  printf("%d\n", ans);
}
