#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return x * f;
}
const int N = 200005;
vector<int> l;
int cnt, head[N], u, v, n, m, tot, vis[N], sc, number, yi, ling;
long long dep[N], ji[65], ans, w, pow2[65], used;
struct node {
  int to, next;
  long long w;
} num[N * 2];
void add(int x, int y, long long w) {
  num[++cnt].to = y;
  num[cnt].next = head[x];
  num[cnt].w = w;
  head[x] = cnt;
}
long long c2(int x) { return (long long)x * (x - 1) / 2; }
void ins(long long x) {
  used |= x;
  for (int i = 60; i >= 0; i--) {
    if ((x >> i) & 1)
      if (!ji[i]) {
        ji[i] = x;
        number++;
        break;
      } else
        x ^= ji[i];
    if (!x) break;
  }
}
void dfs(int x, int fa) {
  vis[x] = sc;
  l.push_back(x);
  for (int i = head[x]; i; i = num[i].next)
    if (num[i].to != fa)
      if (!vis[num[i].to]) {
        dep[num[i].to] = dep[x] ^ num[i].w;
        dfs(num[i].to, x);
      } else
        ins(dep[x] ^ dep[num[i].to] ^ num[i].w);
}
int main() {
  pow2[0] = 1;
  for (int i = 1; i <= 60; i++) pow2[i] = (long long)pow2[i - 1] * 2 % mod;
  n = read();
  m = read();
  for (int i = 1; i <= m; i++)
    u = read(), v = read(), w = read(), add(u, v, w), add(v, u, w);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      ++sc;
      dfs(i, -1);
      for (int k = 60; k >= 0; k--) {
        yi = 0;
        ling = 0;
        for (int j = 0; j < l.size(); j++)
          if ((dep[l[j]] >> k) & 1)
            yi++;
          else
            ling++;
        if (!((used >> k) & 1))
          (ans += (long long)pow2[number] * yi % mod * ling % mod * pow2[k] %
                  mod) %= mod;
        else
          (ans +=
           (long long)pow2[number - 1] * yi % mod * ling % mod * pow2[k] % mod +
           (long long)pow2[number - 1] * ((long long)c2(yi) + c2(ling)) % mod *
               pow2[k] % mod) %= mod;
      }
      l.clear();
      used = 0;
      number = 0;
      memset(ji, 0, sizeof(ji));
    }
  printf("%lld\n", ans % mod);
  return 0;
}
