#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7, MXN = 1e5 + 100, MXM = 2e5 + 100, N = 60;
struct elist {
  int v, last;
  long long w;
} e[MXM + MXM];
int zh[MXN], tote;
void adde(int u, int v, long long w) {
  e[tote].v = v;
  e[tote].w = w;
  e[tote].last = zh[u];
  zh[u] = tote++;
}
bool vis[MXN];
long long sum[MXN], vec[MXM + MXM];
int sumodd[N], odd[MXN][N], even[MXN][N], subn, tot;
void dfs(int u, int fa) {
  subn++;
  vis[u] = 1;
  for (int j = 0; j < N; j++) {
    even[u][j] = 1;
    odd[u][j] = 0;
  }
  for (int i = zh[u]; i != -1; i = e[i].last)
    if (!vis[e[i].v]) {
      sum[e[i].v] = sum[u] ^ e[i].w;
      dfs(e[i].v, u);
      for (int j = 0; j < N; j++) {
        if (e[i].w >> j & 1) {
          odd[u][j] += even[e[i].v][j];
          even[u][j] += odd[e[i].v][j];
        } else {
          odd[u][j] += odd[e[i].v][j];
          even[u][j] += even[e[i].v][j];
        }
      }
    } else if (e[i].v != fa) {
      vec[tot++] = sum[e[i].v] ^ sum[u] ^ e[i].w;
    }
}
int two[MXM], cnt;
bool flag[N];
int main() {
  two[0] = 1;
  for (int i = 1; i < MXM; i++) two[i] = (two[i - 1] << 1) % Mod;
  tote = 0;
  memset(zh, -1, sizeof(zh));
  int n, m, ans = 0;
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    long long w;
    scanf("%d%d%I64d", &u, &v, &w);
    adde(u, v, w);
    adde(v, u, w);
  }
  for (int u = 1; u <= n; u++)
    if (!vis[u]) {
      subn = 0;
      tot = 0;
      dfs(u, -1);
      for (int i = 0; i < N; i++)
        sumodd[i] = 1ll * odd[u][i] * even[u][i] % Mod;
      for (int i = 0, j = 0; j < N && i < tot; j++) {
        for (int k = i + 1; k < tot && (~vec[i] >> j & 1); k++)
          swap(vec[i], vec[k]);
        if (vec[i] >> j & 1) {
          for (int k = i + 1; k < tot; k++)
            if (vec[k] >> j & 1) vec[k] ^= vec[i];
          i++;
        }
      }
      memset(flag, 0, sizeof(flag));
      cnt = 0;
      for (int i = 0; i < tot; i++)
        if (vec[i]) {
          cnt++;
          for (int j = 0; j < N; j++)
            if (vec[i] >> j & 1) flag[j] = 1;
        }
      for (int i = 0; i < N; i++) {
        if (flag[i])
          ans = (1ll * ans + 1ll * subn * (subn - 1) / 2 % Mod * two[cnt - 1] %
                                 Mod * two[i] % Mod) %
                Mod;
        else
          ans = (1ll * ans + 1ll * sumodd[i] * two[cnt] % Mod * two[i] % Mod) %
                Mod;
      }
    }
  printf("%d\n", ans);
  return 0;
}
