#include <bits/stdc++.h>
using namespace std;
long long tavan(long long x, long long y) {
  long long res = 1;
  while (y) {
    res *= y % 2 ? x : 1;
    res %= ((long long)1e9 + 7);
    x *= x;
    x %= ((long long)1e9 + 7);
    y /= 2;
  }
  return res;
}
long long n, m, ans, prt_xr[((long long)101 * 1000)],
    cnt_bit[2][((long long)60)], cnt_comp;
vector<pair<long long, long long> > e[((long long)101 * 1000)];
vector<long long> cycles;
bool mark[((long long)101 * 1000)];
long long mul(long long x, long long y) {
  return ((x % ((long long)1e9 + 7)) * (y % ((long long)1e9 + 7))) %
         ((long long)1e9 + 7);
}
void dfs_cycle(long long x, long long par = 0) {
  for (long long i = 0; i < ((long long)60); i++)
    cnt_bit[((prt_xr[x] & (1LL << i)) != 0)][i]++;
  mark[x] = 1;
  cnt_comp++;
  for (auto u : e[x]) {
    if (u.first == par) continue;
    if (mark[u.first])
      cycles.push_back((u.second ^ prt_xr[x] ^ prt_xr[u.first]));
    else
      prt_xr[u.first] = (prt_xr[x] ^ u.second), dfs_cycle(u.first, x);
  }
}
long long eliminate() {
  long long res = 0, cnt = 1;
  bool one[((long long)60)] = {};
  for (long long i = 0; i < ((long long)60); i++) {
    long long id = -1;
    for (long long j = 0; j < cycles.size(); j++)
      if ((cycles[j] & (1LL << i))) id = j;
    if (id == -1) continue;
    for (long long j = 0; j < ((long long)60); j++)
      one[j] |= ((cycles[id] & (1LL << j)) != 0);
    cnt *= 2;
    cnt %= ((long long)1e9 + 7);
    long long ex = cycles[id];
    for (long long j = 0; j < cycles.size(); j++)
      if ((cycles[j] & (1LL << i))) cycles[j] ^= ex;
  }
  for (long long i = 0; i < ((long long)60); i++) {
    if (one[i])
      res += (((((cnt * tavan(2, ((long long)1e9 + 7) - 2)) %
                 ((long long)1e9 + 7)) *
                (((cnt_comp * (cnt_comp - 1)) / 2) % ((long long)1e9 + 7))) %
               ((long long)1e9 + 7)) *
              ((1LL << i) % ((long long)1e9 + 7))) %
             ((long long)1e9 + 7),
          res %= ((long long)1e9 + 7);
    else
      res +=
          (((cnt * ((cnt_bit[0][i] * cnt_bit[1][i]) % ((long long)1e9 + 7))) %
            ((long long)1e9 + 7)) *
           ((1LL << i) % ((long long)1e9 + 7))) %
          ((long long)1e9 + 7),
          res %= ((long long)1e9 + 7);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    e[v].push_back({u, w});
    e[u].push_back({v, w});
  }
  for (long long i = 1; i <= n; i++)
    if (!mark[i]) {
      cnt_comp = 0;
      cycles.clear();
      memset(cnt_bit, 0, sizeof cnt_bit);
      dfs_cycle(i);
      ans += eliminate();
      ans %= ((long long)1e9 + 7);
    }
  cout << ans;
  return 0;
}
