#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int maxm = 2e5 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int xx[] = {0, 0, 1, -1};
int yy[] = {1, -1, 0, 0};
int N, M, K;
vector<pair<int, long long> > vec[maxn];
vector<int> V;
vector<long long> S;
int vis[maxn];
long long value[maxn];
void dfs(int u, int p, long long s) {
  if (vis[u]) {
    S.push_back(value[u] ^ s);
    return;
  }
  vis[u] = 1;
  V.push_back(u);
  value[u] = s;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i].first;
    long long w = vec[u][i].second;
    if (v == p) continue;
    dfs(v, u, s ^ w);
  }
}
long long ans;
void work() {
  int i2 = 0;
  long long A = 0;
  for (int j = 0; j < S.size(); j++) A |= S[j];
  for (int i = 0; i < 60; i++) {
    int s = -1;
    for (int j = i2; j < S.size(); j++) {
      long long v = S[j];
      if (v & (1ll << i)) {
        s = j;
      }
    }
    if (s == -1) continue;
    swap(S[i2], S[s]);
    for (int j = i2 + 1; j < S.size(); j++) {
      long long &v = S[j];
      if (v & (1ll << i)) {
        v ^= S[i2];
      }
    }
    i2++;
  }
  for (int i = 0; i < 60; i++) {
    if (A & (1ll << i)) {
      ans += (1ll << i) % mod * ((1ll << i2 - 1) % mod) % mod *
             (1ll * V.size() * (V.size() - 1) / 2 % mod);
      ans %= mod;
    } else {
      int X = 0, Y = 0;
      for (int j = 0; j < V.size(); j++) {
        int v = V[j];
        if (value[v] & (1ll << i)) {
          X++;
        } else
          Y++;
      }
      ans += 1ll * X * Y % mod * ((1ll << i2) % mod) % mod * ((1ll << i) % mod);
      ans %= mod;
    }
  }
}
int main(int argc, char *argv[]) {
  if (argc > 1) {
    freopen(argv[1], "r", stdin);
  }
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    long long c;
    scanf("%d%d%lld", &a, &b, &c);
    vec[b].push_back(make_pair(a, c));
    vec[a].push_back(make_pair(b, c));
  }
  for (int i = 1; i <= N; i++) {
    V.clear();
    S.clear();
    if (vis[i]) continue;
    dfs(i, 0, 0);
    work();
  }
  cout << ans << endl;
  return 0;
}
