#include <bits/stdc++.h>
using namespace std;
const long long kMaxN = 100005;
long long Xor[kMaxN];
vector<pair<long long, long long>> G[kMaxN];
long long D[kMaxN], Viz[kMaxN];
vector<long long> Values;
vector<long long> Xors;
const long long kMod = 1e9 + 7;
namespace ModOps {
long long add(long long a, long long b) {
  a += b;
  if (a >= kMod) a -= kMod;
  return a;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += kMod;
  return a;
}
long long mul(long long a, long long b) { return 1LL * a * b % kMod; }
long long lgpow(long long b, long long e) {
  long long r = 1;
  while (e) {
    if (e % 2) r = mul(r, b);
    b = mul(b, b);
    e /= 2;
  }
  return r;
}
long long inv(long long x) { return lgpow(x, kMod - 2); }
};  // namespace ModOps
using namespace ModOps;
void DFS(long long node) {
  Viz[node] = 1;
  Xors.push_back(Xor[node]);
  for (auto e : G[node]) {
    long long vec = e.first;
    long long val = e.second;
    if (!Viz[vec]) {
      Xor[vec] = Xor[node] ^ val;
      D[vec] = D[node] + 1;
      DFS(vec);
    } else if (D[vec] < D[node] - 1) {
      Values.push_back(Xor[node] ^ Xor[vec] ^ val);
    }
  }
}
long long reunion;
vector<long long> Gauss() {
  long long now = 0;
  for (long long bit = 0; bit < 62; ++bit) {
    for (long long i = now; i < Values.size(); ++i) {
      if (Values[i] & (1LL << bit)) {
        swap(Values[i], Values[now]);
        break;
      }
    }
    if (now == Values.size()) continue;
    if (Values[now] & (1LL << bit)) {
      for (long long i = now + 1; i < Values.size(); ++i) {
        if (Values[i] & (1LL << bit)) Values[i] ^= Values[now];
      }
      ++now;
    }
  }
  return vector<long long>(Values.begin(), Values.begin() + now);
}
long long SolveFor(long long i) {
  Values.clear();
  Xors.clear();
  DFS(i);
  auto Base = Gauss();
  long long dim = Base.size();
  assert(dim <= 62);
  long long reunion = 0;
  for (auto x : Base) reunion |= x;
  long long ret = 0, pw = 1;
  for (long long bit = 0; bit < 62; ++bit) {
    long long count_no, count_yes;
    if (reunion & (1LL << bit)) {
      count_no = count_yes = (1LL << (dim - 1));
    } else {
      count_no = (1LL << dim);
      count_yes = 0;
    }
    long long a = 0, b = 0;
    for (auto v : Xors) {
      if (v & (1LL << bit))
        a += 1;
      else
        b += 1;
    }
    long long coef_1 = count_no % kMod;
    coef_1 = mul(coef_1, a);
    coef_1 = mul(coef_1, b);
    long long coef_2 = count_yes % kMod;
    coef_2 = mul(coef_2, add(a * (a - 1) / 2 % kMod, b * (b - 1) / 2 % kMod));
    long long total = add(coef_1, coef_2);
    ret = add(ret, mul(total, pw));
    pw = add(pw, pw);
  }
  return ret;
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  while (m--) {
    long long a, b;
    long long c;
    cin >> a >> b >> c;
    G[a].emplace_back(b, c);
    G[b].emplace_back(a, c);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) {
    if (!Viz[i]) {
      ans = add(ans, SolveFor(i));
    }
  }
  cout << ans << endl;
  return 0;
}
