#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e9 + 7;
int rep[N];
void init() {
  for (int i = 0; i < N; i++) rep[i] = i;
}
int find(int u) {
  if (u == rep[u]) return u;
  return rep[u] = find(rep[u]);
}
bool merge(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return false;
  rep[u] = v;
  return true;
}
struct Edge {
  int u, v;
  long long x;
  int other(int z) { return z ^ u ^ v; }
};
vector<Edge> edges;
vector<int> adj[N], extra[N];
long long cc[N];
vector<int> comp;
void dfs(int u, int p) {
  comp.push_back(u);
  for (int id : adj[u]) {
    int v = edges[id].other(u);
    long long x = edges[id].x;
    if (v == p) continue;
    cc[v] = cc[u] ^ x;
    dfs(v, u);
  }
}
const int K = 61;
long long rr[K];
int p2[2 * K];
int rnk = 0;
vector<int> order;
void ini() {
  memset(rr, -1, sizeof rr);
  rnk = 0;
  order.clear();
}
void add(long long x) {
  for (int i = 0; i < K; i++) {
    if (rr[i] == -1) continue;
    if (x & (1LL << i)) x ^= rr[i];
  }
  if (x == 0) return;
  int id = __builtin_ctzll(x);
  rr[id] = x;
  order.push_back(id);
  rnk++;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  init();
  p2[0] = 1;
  for (int i = 1; i < 2 * K; i++) p2[i] = (p2[i - 1] * 2) % M;
  vector<int> ex;
  while (m--) {
    int u, v;
    long long x;
    cin >> u >> v >> x;
    edges.push_back({u, v, x});
    int id = edges.size() - 1;
    if (merge(u, v))
      adj[u].push_back(id), adj[v].push_back(id);
    else
      ex.push_back(id);
  }
  for (int id : ex) extra[find(edges[id].u)].push_back(id);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (rep[i] != i) continue;
    ini();
    comp.clear();
    dfs(i, -1);
    long long mask = 0;
    for (int id : extra[i]) {
      int u = edges[id].u;
      int v = edges[id].v;
      long long x = edges[id].x;
      long long cxor = cc[u] ^ cc[v] ^ x;
      mask |= cxor;
      add(cxor);
    }
    int k = comp.size();
    long long prs = (1LL * k * (k - 1) / 2) % M;
    long long ways = (rnk ? (1LL << (rnk - 1)) : 0) % M;
    ways = (ways * prs) % M;
    for (int i = 0; i <= 60; i++) {
      if (mask & (1LL << i))
        ans = (ans + ways * p2[i]) % M;
      else {
        int one = 0, zero = 0;
        for (int u : comp)
          if (cc[u] & (1LL << i))
            one++;
          else
            zero++;
        if (!zero || !one) continue;
        ans = (ans + 1LL * zero * one * p2[i + rnk]) % M;
      }
    }
  }
  cout << ans << endl;
}
