#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, m;
vector<pair<int, long long> > vec[100100];
long long dis[100100];
vector<int> rt;
vector<long long> mat;
long long ans = 0;
void dfs(int a, int p, long long d) {
  dis[a] = d;
  rt.push_back(a);
  for (int i = 0; i < vec[a].size(); i++) {
    if (vec[a][i].first == p) continue;
    if (dis[vec[a][i].first] == -1)
      dfs(vec[a][i].first, a, d ^ vec[a][i].second);
    else
      mat.push_back(d ^ dis[vec[a][i].first] ^ vec[a][i].second);
  }
}
void guess() {
  int now = 0;
  for (int i = 0; i < 60; i++) {
    int j = 0;
    for (j = now; j < mat.size() && !(mat[j] >> i & 1); j++)
      ;
    if (j == mat.size()) {
      continue;
    }
    swap(mat[j], mat[now]);
    for (j = now + 1; j < mat.size(); j++)
      if (mat[j] >> i & 1) mat[j] ^= mat[now];
    now++;
  }
  mat.resize(now);
}
int power(long long a, long long k) {
  long long p = 1;
  while (k) {
    if (k & 1) p = p * a % MOD;
    a = a * a % MOD;
    k >>= 1;
  }
  return int(p);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    long long w;
    scanf("%d%d%lld", &u, &v, &w);
    vec[u].push_back(make_pair(v, w));
    vec[v].push_back(make_pair(u, w));
  }
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i <= n; i++) {
    if (dis[i] == -1) {
      rt.clear();
      mat.clear();
      dfs(i, 0, 0);
      guess();
      int all[65][2], mm[65][2];
      memset(all, 0, sizeof(all));
      memset(mm, 0, sizeof(mm));
      for (int j = 0; j < rt.size(); j++)
        for (int k = 0; k < 60; k++) all[k][(dis[rt[j]] >> k) & 1ll]++;
      for (int j = 0; j < mat.size(); j++)
        for (int k = 0; k < 60; k++) mm[k][(mat[j] >> k) & 1]++;
      long long res = all[0][0] + all[0][1];
      res = res * (res - 1) / 2;
      for (int k = 0; k < 60; k++) {
        ans = (ans + (long long)all[k][0] * all[k][1] *
                         power(2, mm[k][0] + max(0, mm[k][1] - 1)) % MOD *
                         power(2, k)) %
              MOD;
        if (mm[k][1])
          ans = (ans + (long long)(res - (long long)all[k][0] * all[k][1]) %
                           MOD * power(2, mm[k][0] + mm[k][1] - 1) % MOD *
                           power(2, k)) %
                MOD;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
