#include <bits/stdc++.h>
template <typename T>
bool domax(T &a, T b) {
  return (b > a ? (a = b, true) : false);
}
template <typename T>
bool domin(T &a, T b) {
  return (b < a ? (a = b, true) : false);
}
const int maxn = 100 * 1000 + 5, maxb = 61;
const long long Mod = 1000 * 1000 * 1000 + 7;
int n, m;
std::vector<std::pair<int, long long>> e[maxn];
bool seen[maxn], done[maxn];
long long xorto[maxn], c[2][maxb + 5], d[2][maxb + 5], ans;
std::vector<long long> cycles;
void go(int i, int p) {
  seen[i] = true;
  for (auto &k : e[i]) {
    int j;
    long long t;
    std::tie(j, t) = k;
    if (j == p) continue;
    if (seen[j]) {
      cycles.push_back(xorto[i] ^ xorto[j] ^ t);
    } else {
      xorto[j] = xorto[i] ^ t;
      go(j, i);
    }
  }
}
void dobits(long long &t) {
  for (int i = 0; i < maxb; i++)
    if (t & (1ll << i)) std::swap(c[0][i], c[1][i]);
}
void add(long long &a, long long b) {
  a += b;
  if (a >= Mod) a -= Mod;
}
void ho(int i, int p) {
  done[i] = true;
  for (int i = 0; i < maxb; i++) {
    add(d[0][i], ((c[0][i]) % Mod));
    add(d[1][i], ((c[1][i]) % Mod));
  }
  for (int i = 0; i < maxb; i++) c[0][i]++;
  for (auto &k : e[i]) {
    int j;
    long long t;
    std::tie(j, t) = k;
    if (j == p) continue;
    if (!done[j]) {
      dobits(t);
      ho(j, i);
      dobits(t);
    }
  }
}
void simplify(std::vector<long long> &v) {
  std::priority_queue<long long> q;
  for (long long &l : v)
    if (l) q.push(l);
  v.clear();
  while ((int((q).size())) >= 2) {
    long long l = q.top();
    q.pop();
    long long m = q.top();
    if ((l & m) * 2 > l) {
      if (l ^ m) q.push(l ^ m);
    } else {
      v.push_back(l);
    }
  }
  while (!q.empty()) {
    v.push_back(q.top());
    q.pop();
  }
}
void solve(int r) {
  cycles.clear();
  go(r, -1);
  simplify(cycles);
  for (int i = 0; i < maxb; i++) c[0][i] = c[1][i] = 0;
  for (int i = 0; i < maxb; i++) d[0][i] = d[1][i] = 0;
  ho(r, -1);
  for (int i = 0; i < maxb; i++) {
    long long d0 = d[0][i], d1 = d[1][i];
    for (long long &l : cycles) {
      if (l & (1ll << i)) {
        add(d1, d0);
        d0 = d1;
      } else {
        add(d1, d1);
        add(d0, d0);
      }
    }
    add(ans, ((d1 * ((1ll << i) % Mod)) % Mod));
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    long long t;
    scanf("%d%d%lld", &u, &v, &t);
    u--;
    v--;
    e[u].emplace_back(v, t);
    e[v].emplace_back(u, t);
  }
  for (int i = 0; i < n; i++)
    if (!seen[i]) solve(i);
  printf("%lld\n", ans);
}
