#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
vector<pair<int, long long>> G[maxn];
long long dep[maxn];
bool vis[maxn];
vector<long long> loops;
vector<long long> nums;
inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
void dfs(int u) {
  nums.push_back(dep[u]);
  vis[u] = true;
  for (auto &p : G[u]) {
    int v = p.first;
    long long w = p.second;
    if (!vis[v]) {
      dep[v] = dep[u] ^ w;
      dfs(v);
    } else if (dep[v] ^ dep[u] ^ w)
      loops.push_back(dep[v] ^ dep[u] ^ w);
  }
}
int dp[2][66][2];
int pw[66];
int cnt[66];
int solve(int rt) {
  loops.clear();
  nums.clear();
  dfs(rt);
  int r = 0;
  for (int i = 0; i < 61; ++i) {
    int id = -1;
    for (int j = r; j < loops.size(); ++j)
      if (loops[j] >> i & 1) {
        id = j;
        break;
      }
    if (id == -1) continue;
    if (id != r) swap(loops[id], loops[r]);
    for (int j = r + 1; j < loops.size(); ++j)
      if (loops[j] >> i & 1) loops[j] ^= loops[r];
    ++r;
  }
  auto &x = dp[0], &y = dp[1];
  for (int i = 0; i < 61; ++i) y[i][0] = 1, y[i][1] = 0;
  for (int i = 0; i < r; ++i) {
    swap(x, y);
    for (int j = 0; j < 61; ++j) {
      y[j][0] = x[j][0];
      y[j][1] = x[j][1];
      if (loops[i] >> j & 1) {
        add(y[j][0], x[j][1]);
        add(y[j][1], x[j][0]);
      } else {
        add(y[j][0], x[j][0]);
        add(y[j][1], x[j][1]);
      }
    }
  }
  for (int i = 0; i < 61; ++i) cnt[i] = 0;
  for (long long x : nums)
    for (int i = 0; i < 61; ++i) cnt[i] += x >> i & 1;
  int ret = 0;
  for (int i = 0; i < 61; ++i) {
    int a = cnt[i], b = nums.size() - cnt[i];
    int one = 1ll * a * b % mod;
    int zero =
        (1ll * a * (a - 1) / 2 % mod + 1ll * b * (b - 1) / 2 % mod) % mod;
    add(ret, 1ll * one * pw[i] % mod * y[i][0] % mod);
    add(ret, 1ll * zero * pw[i] % mod * y[i][1] % mod);
  }
  return ret;
}
int main() {
  pw[0] = 1;
  for (int i = 1; i < 66; ++i) {
    pw[i] = pw[i - 1] + pw[i - 1];
    if (pw[i] >= mod) pw[i] -= mod;
  }
  int n, m;
  scanf("%d %d", &n, &m);
  while (m--) {
    int u, v;
    long long t;
    scanf("%d %d %I64d", &u, &v, &t);
    G[u].emplace_back(v, t);
    G[v].emplace_back(u, t);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) add(ans, solve(i));
  printf("%d\n", ans);
  return 0;
}
