#include <bits/stdc++.h>
using namespace std;
inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; }
inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; }
const int maxn = 100100;
int n, m, u, v;
long long w;
long long x[maxn];
bool vis[maxn], ins[maxn];
vector<pair<int, long long> > g[maxn];
vector<long long> cir, val;
void dfs(int t, int fa, long long s) {
  x[t] = s;
  val.push_back(x[t]);
  vis[t] = 1;
  ins[t] = 1;
  for (auto e : g[t]) {
    int v = e.first;
    long long w = e.second;
    if (v == fa) continue;
    if (ins[v]) {
      cir.push_back(x[t] ^ x[v] ^ w);
    } else {
      if (!vis[v]) dfs(v, t, s ^ w);
    }
  }
  ins[t] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%lld", &u, &v, &w);
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      cir.clear();
      val.clear();
      dfs(i, 0, 0);
      int cnt = 0;
      for (int i = 0, j = 0; i < 60; ++i) {
        long long val = 0;
        int p = 0;
        for (int k = j; k < cir.size(); ++k)
          if ((cir[k] >> i) & 1) val = cir[k], p = k;
        if (!val) continue;
        swap(cir[j], cir[p]);
        for (int k = j + 1; k < cir.size(); ++k)
          if ((cir[k] >> i) & 1) cir[k] ^= val;
        j++;
        cnt++;
      }
      for (int i = 0; i < 60; ++i) {
        bool flag = 0;
        for (int j = 0; j < cnt; ++j)
          if ((cir[j] >> i) & 1) flag = 1;
        int cnt0 = 0, cnt1 = 0;
        for (auto v : val)
          if ((v >> i) & 1)
            cnt1++;
          else
            cnt0++;
        int base = (1LL << i) % 1000000007;
        if (flag) {
          int bb = (1LL << (cnt - 1)) % 1000000007, tot = cnt1 + cnt0;
          ans = (ans + (long long)base * bb % 1000000007 *
                           ((long long)tot * (tot - 1) / 2 % 1000000007) %
                           1000000007) %
                1000000007;
        } else {
          int bb = (1LL << cnt) % 1000000007;
          ans = (ans + (long long)base * bb % 1000000007 * cnt1 % 1000000007 *
                           cnt0 % 1000000007) %
                1000000007;
        }
      }
    }
  printf("%d\n", ans);
  return 0;
}
