#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long INF = 1011111111;
const long long LLINF = 1000111000111000111LL;
const long double EPS = 1e-10;
const long double PI = 3.14159265358979323;
using namespace std;
long long powm(long long base, long long exp, long long mod = MOD) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
const long long N = 1000005;
struct gauss {
  long long basis[61], dim;
  void reset() {
    dim = 0;
    for (long long i = 0; i < 61; i++) basis[i] = 0;
  }
  void add(long long x) {
    for (long long i = 60; i >= 0; i--) {
      if ((x >> i) & 1) {
        if (basis[i])
          x ^= basis[i];
        else {
          basis[i] = x;
          dim++;
          return;
        }
      }
    }
  }
} gaussian;
vector<pair<long long, long long>> adj[N];
long long vis[N], pref[N];
long long bits_set, cnt[2][61], comp_size;
void dfs(long long curr, long long par) {
  vis[curr] = 1;
  comp_size++;
  for (long long i = 0; i < 60; i++) cnt[(pref[curr] >> i) & 1][i]++;
  for (auto i : adj[curr])
    if (i.first != par) {
      if (!vis[i.first]) {
        pref[i.first] = pref[curr] ^ i.second;
        dfs(i.first, curr);
      } else {
        gaussian.add(pref[curr] ^ pref[i.first] ^ i.second);
      }
    }
}
long long p2[61];
int32_t main() {
  for (long long i = 0; i < 61; i++) p2[i] = (1LL << i) % MOD;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long u, v, w, n, m;
  cin >> n >> m;
  while (m--) {
    cin >> u >> v >> w;
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  long long ans = 0;
  for (long long iter = 1; iter < n + 1; iter++)
    if (!vis[iter]) {
      gaussian.reset();
      bits_set = 0;
      comp_size = 0;
      for (long long i = 0; i < 61; i++) cnt[0][i] = cnt[1][i] = 0;
      dfs(iter, 0);
      for (long long i = 0; i < 60; i++) bits_set |= gaussian.basis[i];
      for (long long i = 0; i < 60; i++) {
        long long curr = 0;
        if ((bits_set >> i) & 1) {
          curr = (p2[i] * p2[gaussian.dim - 1]) % MOD;
          curr = (curr * ((comp_size * (comp_size - 1)) / 2) % MOD) % MOD;
        } else {
          curr = (p2[i] * p2[gaussian.dim]) % MOD;
          curr = (curr * cnt[0][i]) % MOD;
          curr = (curr * cnt[1][i]) % MOD;
        }
        ans = (ans + curr) % MOD;
      }
    }
  cout << ans;
  return 0;
}
