#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int K = 61;
const int MOD = 1e9 + 7;
int cnt[K][2];
long long basis[K];
vector<pair<int, long long> > adj[MAX];
long long val[MAX];
int vis[MAX];
int sz = 0;
long long bor = 0;
void add(long long wt) {
  for (int i = 0; i < K; i++) {
    ++cnt[i][(wt >> i) & 1];
  }
}
void add_cycle(long long wt) {
  bor |= wt;
  for (int i = K - 1; i >= 0; i--) {
    if ((wt >> i) & 1) {
      if (basis[i]) {
        wt ^= basis[i];
      } else {
        basis[i] = wt;
        ++sz;
        break;
      }
    }
  }
}
void dfs(int s, int p) {
  add(val[s]);
  vis[s] = 1;
  for (auto v : adj[s]) {
    int u = v.first;
    long long wt = v.second;
    if (u != p) {
      if (vis[u]) {
        add_cycle(val[s] ^ wt ^ val[u]);
      } else {
        val[u] = val[s] ^ wt;
        dfs(u, s);
      }
    }
  }
}
long long pw2[MAX + K + K];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    long long w;
    scanf("%d %d %lld", &a, &b, &w);
    adj[a].push_back(make_pair(b, w));
    adj[b].push_back(make_pair(a, w));
  }
  pw2[0] = 1;
  for (int i = 1; i < (MAX + K + K); i++) {
    pw2[i] = (pw2[i - 1] * 2) % MOD;
  }
  long long ans = 0;
  for (int j = 1; j <= n; j++) {
    if (!vis[j]) {
      sz = 0;
      bor = 0;
      memset(cnt, 0, sizeof(cnt));
      memset(basis, 0, sizeof(basis));
      dfs(j, 0);
      for (int i = 0; i < K; i++) {
        if ((bor >> i) & 1) {
          ans += ((((((cnt[i][0] + cnt[i][1]) * 1ll *
                      (cnt[i][0] + cnt[i][1] - 1)) /
                     2) %
                    MOD) *
                   pw2[i + sz - 1]) %
                  MOD);
          ans %= MOD;
        } else {
          ans += ((((cnt[i][0] * 1ll * cnt[i][1]) % MOD) * pw2[i + sz]) % MOD);
          ans %= MOD;
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
