#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int NMAX = 111111, MMAX = 222222;
const int KMAX = 60;
bool visited[NMAX], visited2[NMAX];
long long to_root[NMAX];
long long dp[NMAX][KMAX][2];
vector<int> g[NMAX];
int U[MMAX], V[MMAX];
long long T[MMAX];
int subsize[NMAX];
long long ans;
long long basis(vector<long long>& v) {
  int pivot = -1;
  for (int i = 0; i < KMAX; i++) {
    int idx = -1;
    for (int j = pivot + 1; j < v.size(); j++) {
      if (v[j] & (1LL << i)) {
        idx = j;
        break;
      }
    }
    if (idx >= 0) {
      pivot++;
      swap(v[idx], v[pivot]);
      for (int j = pivot + 1; j < v.size(); j++) {
        if (v[j] & (1LL << i)) v[j] ^= v[pivot];
      }
    }
  }
  long long ret = 0;
  for (long long x : v) ret |= x;
  return ret;
}
void dfs(int u, int fa, vector<int>& rest) {
  subsize[u] = 1;
  for (int e : g[u]) {
    int v = U[e] + V[e] - u;
    long long t = T[e];
    if (!visited[v]) {
      visited[v] = true;
      to_root[v] = to_root[u] ^ t;
      dfs(v, u, rest);
      subsize[u] += subsize[v];
    } else if (v != fa) {
      rest.push_back(e);
    }
  }
}
void dfs2(int u) {
  for (int i = 0; i < KMAX; i++) dp[u][i][0] = 1;
  for (int e : g[u]) {
    int v = U[e] + V[e] - u;
    if (!visited2[v]) {
      visited2[v] = true;
      dfs2(v);
      for (int i = 0; i < KMAX; i++) {
        int dif = 0;
        if (T[e] & (1LL << i)) dif = 1;
        for (int j = 0; j < 2; j++) {
          dp[u][i][j ^ dif] = (dp[u][i][j ^ dif] + dp[v][i][j]) % MOD;
        }
      }
    }
  }
}
void process(int u) {
  vector<int> rest;
  visited[u] = true;
  dfs(u, -1, rest);
  sort(rest.begin(), rest.end());
  rest.erase(unique(rest.begin(), rest.end()), rest.end());
  vector<long long> vec;
  for (int e : rest) vec.push_back(to_root[U[e]] ^ to_root[V[e]] ^ T[e]);
  long long b = basis(vec);
  visited2[u] = true;
  dfs2(u);
  long long df = 0;
  for (auto x : vec)
    if (x) df++;
  long long half = 1;
  for (int i = 0; i < df - 1; i++) half = half * 2 % MOD;
  long long tot = 1;
  for (int i = 0; i < df; i++) tot = tot * 2 % MOD;
  long long size = subsize[u];
  long long nc2 = size * (size - 1) / 2 % MOD;
  for (int i = 0; i < KMAX; i++) {
    if (b & (1LL << i)) {
      ans = (ans + (1LL << i) % MOD * nc2 % MOD * half % MOD) % MOD;
    } else {
      ans = (ans + (1LL << i) % MOD * dp[u][i][0] % MOD * dp[u][i][1] % MOD *
                       tot % MOD) %
            MOD;
    }
  }
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int u, v;
    long long t;
    scanf("%d%d%lld", &u, &v, &t);
    g[u].push_back(i), g[v].push_back(i);
    U[i] = u, V[i] = v, T[i] = t;
  }
  for (int i = 1; i <= N; i++)
    if (!visited[i]) process(i);
  printf("%lld", ans);
}
