#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int N = 2e5 + 5;
const int M = 63;
long long read() {
  long long s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
long long dis[N];
int n, m, cnt, Size, h[N], p[N], vis[N], num[M];
struct edge {
  int to, next;
  long long dist;
} d[N * 2];
void Add(int x, int y, long long z) {
  d[++cnt] = (edge){y, h[x], z};
  h[x] = cnt;
}
struct Line_Basis {
  long long p[M], num;
  void Clear() {
    num = 0;
    memset(p, 0, sizeof(p));
  }
  void Insert(long long x) {
    for (int i = M - 1; i >= 0; i--)
      if ((x >> i) & 1) {
        if (!p[i]) {
          p[i] = x;
          num++;
          break;
        }
        x ^= p[i];
      }
  }
  void Build() {
    for (int i = M - 1; i >= 0; i--)
      for (int j = i - 1; j >= 0; j--)
        if ((p[i] >> j) & 1) p[i] ^= p[j];
  }
} F;
int mod(int x) { return x >= Mod ? x - Mod : x; }
void DFS(int x, long long dist) {
  vis[x] = 1;
  dis[x] = dist;
  Size++;
  for (int i = 0; i < M; i++) num[i] += (dis[x] >> i) & 1;
  for (int i = h[x]; i; i = d[i].next) {
    int y = d[i].to;
    if (!vis[y])
      DFS(y, dist ^ d[i].dist);
    else
      F.Insert(dis[x] ^ dis[y] ^ d[i].dist);
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    long long z = read();
    Add(x, y, z);
    Add(y, x, z);
  }
  int Ans = 0;
  p[0] = 1;
  for (int i = 1; i < N; i++) p[i] = mod(p[i - 1] << 1);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      long long Max = 0;
      Size = 0;
      memset(num, 0, sizeof(num));
      F.Clear();
      DFS(i, 0);
      F.Build();
      for (int i = 0; i < M; i++) Max |= F.p[i];
      for (int i = 0; i < M; i++) {
        if ((Max >> i) & 1)
          Ans = mod(Ans + 1ll * (1ll * Size * (Size - 1) / 2) % Mod * p[i] %
                              Mod * p[F.num - 1] % Mod);
        else
          Ans = mod(Ans + 1ll * num[i] * (Size - num[i]) % Mod * p[i] % Mod *
                              p[F.num] % Mod);
      }
    }
  }
  printf("%d", Ans);
  return 0;
}
