#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
bool vis[100005];
vector<pair<int, long long> > g[100005];
long long dp[100005], vec[60];
int cnt;
void add(long long v) {
  for (int i = 59; i >= 0; i--) {
    if ((v >> i) & 1) {
      if (vec[i] == -1) {
        vec[i] = v;
        return;
      } else
        v ^= vec[i];
    }
  }
}
int b[2][60];
void dfs(int u) {
  vis[u] = 1;
  cnt++;
  for (int i = 0; i <= 59; i++) {
    if ((dp[u] >> i) & 1)
      b[1][i]++;
    else
      b[0][i]++;
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    long long w = g[u][i].second;
    if (vis[v]) {
      add(dp[u] ^ dp[v] ^ w);
      continue;
    }
    dp[v] = dp[u] ^ w;
    dfs(v);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    long long c;
    scanf("%d%d%lld", &a, &b, &c);
    g[a].push_back(pair<int, long long>(b, c));
    g[b].push_back(pair<int, long long>(a, c));
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    memset(vec, -1, sizeof(vec));
    memset(b, 0, sizeof(b));
    cnt = 0;
    dfs(i);
    int r = 0;
    for (int i = 0; i <= 59; i++) {
      if (vec[i] != -1) r++;
    }
    for (int i = 59; i >= 0; i--) {
      bool ok = 0;
      long long val = (1ll << i) % mod;
      for (int j = 0; j <= 59; j++) {
        if (vec[j] != -1 && ((vec[j] >> i) & 1)) ok = 1;
      }
      if (ok) {
        long long tot = cnt * 1ll * (cnt - 1) / 2 % mod;
        ans = (ans + tot * val % mod * ((1ll << (r - 1)) % mod)) % mod;
      } else {
        long long tot = b[0][i] * 1ll * b[1][i] % mod;
        ans = (ans + tot * val % mod * ((1ll << r) % mod)) % mod;
      }
    }
  }
  printf("%lld\n", ans);
}
