#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 4e5 + 5;
const int mod = 1e9 + 7;
int n, m, x, y, CNT, tot, r, tail, q[N], first[N];
long long w, ans, cnt[2], sum[N], two[65], a[65], cir[M];
bool flag, vis[N];
struct edge {
  int to, next;
  long long w;
} e[M];
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
void ins(int u, int v, long long w) {
  e[++CNT] = (edge){v, first[u], w};
  first[u] = CNT;
}
void dfs(int x, int fa) {
  vis[x] = true;
  q[++tail] = x;
  for (int i = first[x]; i; i = e[i].next) {
    int to = e[i].to;
    if (to == fa) continue;
    if (!vis[to])
      sum[to] = sum[x] ^ e[i].w, dfs(to, x);
    else
      cir[++tot] = sum[x] ^ e[i].w ^ sum[to];
  }
}
void build() {
  r = 0;
  memset(a, 0, sizeof(a));
  for (int i = 1; i <= tot; i++)
    for (int j = 60; j >= 0; j--) {
      if (!(cir[i] & (1ll << j))) continue;
      if (!a[j]) {
        a[j] = cir[i];
        break;
      }
      cir[i] ^= a[j];
    }
  for (int i = 0; i <= 60; i++)
    if (a[i]) r++;
}
long long calc() {
  build();
  long long ans = 0, now;
  for (int i = 0; i <= 60; i++) {
    cnt[0] = cnt[1] = 0;
    flag = false;
    for (int j = 0; j <= 60; j++)
      if (a[j] & (1ll << i)) {
        flag = true;
        break;
      }
    for (int j = 1; j <= tail; j++) cnt[(sum[q[j]] >> i) & 1]++;
    now = (cnt[0] * (cnt[0] - 1) / 2 + cnt[1] * (cnt[1] - 1) / 2) % mod;
    if (flag) ans = (ans + now * two[r - 1] % mod * two[i] % mod) % mod;
    now = cnt[0] * cnt[1] % mod;
    if (!flag)
      ans = (ans + now * two[r] % mod * two[i] % mod) % mod;
    else
      ans = (ans + now * two[r - 1] % mod * two[i] % mod) % mod;
  }
  return ans;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    w = read();
    ins(x, y, w);
    ins(y, x, w);
  }
  two[0] = 1;
  for (int i = 1; i <= 61; i++) two[i] = two[i - 1] * 2 % mod;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    tot = 0;
    tail = 0;
    dfs(i, -1);
    ans = (ans + calc()) % mod;
  }
  printf("%I64d", ans);
  return 0;
}
