#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
vector<pair<int, long long>> mp[100035];
long long dis[100035], B[70];
vector<long long> vt;
bool vis[100035];
int cnt;
void add(long long x) {
  for (int j = 60; j >= 0; j--) {
    if (x & (1LL << j)) {
      if (B[j] == 0) {
        B[j] = x;
        cnt++;
        break;
      } else
        x ^= B[j];
    }
  }
}
void dfs(int x, int pa, long long D) {
  dis[x] = D;
  vt.push_back(D);
  vis[x] = 1;
  for (auto c : mp[x]) {
    int v = c.first;
    long long w = c.second;
    if (v == pa) continue;
    if (vis[v]) {
      add(D ^ dis[v] ^ w);
    } else {
      dfs(v, x, D ^ w);
    }
  }
}
void fmain() {
  scanf("%d%d", &n, &m);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d%lld", &u, &v, &lk);
    mp[u].push_back({v, lk});
    mp[v].push_back({u, lk});
  }
  int ans = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (!vis[i]) {
      cnt = 0;
      vt.clear();
      for (int(i) = 0; (i) < (int)(65); (i)++) B[i] = 0;
      dfs(i, 0, 0);
      for (int j = 60; j >= 0; j--) {
        long long w2 = (1LL << j) % 1000000007;
        bool ok = 0;
        for (int(z) = 0; (z) < (int)(61); (z)++)
          if (B[z] & (1LL << j)) ok = 1;
        if (ok) {
          addmod(ans, w2 * ((long long)vt.size() * (vt.size() - 1) / 2) %
                          1000000007 * fastPow(2, cnt - 1) % 1000000007);
        } else {
          int g = 0;
          for (long long tmp : vt)
            if (tmp & (1LL << j)) g++;
          addmod(ans, (long long)g * (vt.size() - g) % 1000000007 *
                          fastPow(2, cnt) % 1000000007 * w2 % 1000000007);
        }
      }
    }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain();
  }
  return 0;
}
