#include <bits/stdc++.h>
using namespace std;
const int Log = 60;
const int N = 210000;
const int mod = 1e9 + 7;
long long p2[Log + 5];
struct edge {
  int to, nxt;
  long long co;
} e[N * 2];
int h[N], E = 0;
int n, m;
long long lb[Log + 5], tot = 0, cnt[Log + 5], siz[Log + 5];
int used[N], f[N], g[N];
long long lan[N];
vector<int> now;
long long qpow(long long a, long long b) {
  int res = 1;
  for (; b > 0; b /= 2, a = a * a % mod)
    if (b % 2) res = res * a % mod;
  return res;
}
void addedge(int u, int v, long long w) {
  E++;
  e[E].to = v;
  e[E].co = w;
  e[E].nxt = h[u];
  h[u] = E;
  return;
}
void ins(long long x) {
  for (int i = Log; i >= 0; i--) {
    if (!(x & p2[i])) continue;
    if (lb[i] == 0) {
      lb[i] = x, tot++;
      return;
    } else
      x ^= lb[i];
  }
  return;
}
void dfs(int u, int fa, long long co) {
  now.push_back(u);
  used[u] = 1;
  lan[u] = lan[fa] ^ co;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    long long w = e[i].co;
    if (v == fa) continue;
    if (used[v])
      ins(lan[u] ^ lan[v] ^ w);
    else
      dfs(v, u, w);
  }
  return;
}
long long C(int n, int m) {
  if (n < m) return 0;
  return f[n] * g[m] % mod * g[n - m] % mod;
}
long long cal(int root) {
  now.clear();
  tot = 0;
  for (int i = 0; i <= Log; i++) lb[i] = cnt[i] = siz[i] = 0;
  dfs(root, 0, 0);
  for (int i = 0; i <= Log; i++) {
    for (int j = 0; j <= Log; j++) {
      if (lb[i] & p2[j]) cnt[j]++;
    }
  }
  int len = now.size();
  for (int i = 0; i < len; i++) {
    for (int j = 0; j <= Log; j++) {
      if (lan[now[i]] & p2[j]) siz[j]++;
    }
  }
  long long sum = 0;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j <= Log; j++) {
      int t0 = p2[j] & lan[now[i]] ? siz[j] : len - siz[j];
      int t1 = len - t0;
      t0--;
      if (cnt[j] > 0) sum += p2[j] % mod * t0 % mod * qpow(2, tot - 1) % mod;
      sum %= mod;
      if (cnt[j] > 0)
        sum += p2[j] % mod * t1 % mod * qpow(2, tot - 1) % mod;
      else
        sum += p2[j] % mod * t1 % mod * qpow(2, tot) % mod;
      sum %= mod;
    }
  }
  return sum;
}
int main() {
  p2[0] = 1;
  for (int i = 1; i <= Log; i++) p2[i] = p2[i - 1] * 2;
  scanf("%d%d", &n, &m);
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % mod;
  for (int i = 0; i <= n; i++) g[i] = qpow(f[i], mod - 2);
  int u, v;
  long long w;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lld", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    ans += cal(i);
    ans %= mod;
  }
  printf("%lld\n", ans * qpow(2, mod - 2) % mod);
  return 0;
}
