#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2, vLen = 60, mod = 1e9 + 7;
int n, m;
vector<pair<int, long long> > v[N];
int sz, vis[N], Bitscnt[N];
long long Spaceval;
long long xval[N], basis[vLen + 1];
int cntNode = 0;
void insertvector(long long mask) {
  for (int i = vLen; i >= 0; i--) {
    if ((mask & 1LL << i) == 0) continue;
    if (!basis[i]) {
      basis[i] = mask;
      Spaceval |= mask;
      sz++;
      return;
    }
    mask ^= basis[i];
  }
}
void dfs(int node, int par) {
  vis[node]++;
  cntNode++;
  for (int i = vLen; i >= 0; i--)
    if ((xval[node] & 1LL << i) != 0) Bitscnt[i]++;
  for (auto i : v[node]) {
    if (i.first == par) continue;
    if (!vis[i.first]) {
      xval[i.first] = i.second ^ xval[node];
      dfs(i.first, node);
    } else {
      insertvector(xval[node] ^ xval[i.first] ^ i.second);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long val;
    cin >> x >> y >> val;
    v[x].push_back({y, val});
    v[y].push_back({x, val});
  }
  long long ans = 0;
  for (int j = 1; j <= n; j++) {
    if (vis[j]) continue;
    dfs(j, 0);
    for (int i = 0; i < vLen; i++) {
      if ((Spaceval & 1LL << i) == 0) {
        ans += 1LL * Bitscnt[i] * (cntNode - Bitscnt[i]) % mod *
               ((1LL << sz) % mod) % mod * ((1LL << i) % mod) % mod;
        ans %= mod;
      } else {
        ans += 1LL * cntNode * (cntNode - 1) / 2 % mod *
               ((1LL << sz - 1) % mod) % mod * ((1LL << i) % mod) % mod;
        ans %= mod;
      }
    }
    sz = 0;
    cntNode = 0;
    Spaceval = 0;
    memset(Bitscnt, 0, sizeof Bitscnt);
    memset(basis, 0, sizeof basis);
  }
  cout << ans;
}
