#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const long long mod = 1e9 + 7;
int T;
int n, m;
struct graph {
  int head[N], nxt[N << 1], to[N << 1], sz;
  long long w[N << 1];
  void init() { memset(head, 0, sizeof(head)), sz = 0; }
  graph() { init(); }
  void push(int a, int b, long long c) {
    nxt[++sz] = head[a], to[sz] = b, w[sz] = c, head[a] = sz;
  }
  int &operator[](const int a) { return to[a]; }
} g;
bool vis[N];
long long d[N], b[70];
int s[N], t = 0, c;
void insert(long long x) {
  for (int j = 60; j >= 0; j--) {
    if ((x >> j) & 1) {
      if (!b[j]) {
        b[j] = x;
        c++;
        break;
      } else
        x ^= b[j];
    }
  }
}
void dfs(int u, long long val) {
  vis[u] = 1;
  d[u] = val;
  s[++t] = u;
  for (int i = g.head[u]; i; i = g.nxt[i]) {
    if (vis[g[i]])
      insert(val ^ d[g[i]] ^ g.w[i]);
    else
      dfs(g[i], val ^ g.w[i]);
  }
}
long long ans = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long z;
    scanf("%d%d%lld", &x, &y, &z);
    g.push(x, y, z);
    g.push(y, x, z);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      memset(b, 0, sizeof(b));
      c = t = 0;
      dfs(i, 0);
      for (int j = 0; j <= 60; j++) {
        long long cc = (1ll << j) % mod;
        bool ok = 0;
        for (int k = 0; k <= 60; k++)
          if (b[k] >> j & 1) ok = 1;
        if (ok)
          ans = (ans + 1ll * t * (t - 1) / 2 % mod * ((1ll << c - 1) % mod) %
                           mod * cc) %
                mod;
        else {
          int x = 0;
          for (int i = 1; i <= t; i++)
            if (d[s[i]] >> j & 1) ++x;
          ans =
              (ans + 1ll * x * (t - x) % mod * ((1ll << c) % mod) % mod * cc) %
              mod;
        }
      }
    }
  }
  printf("%lld\n", ans % mod);
  return 0;
}
