#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100020, Maxm = 200020, mod = 1e9 + 7;
int n, m;
int eu[Maxm], ev[Maxm];
long long ew[Maxm];
vector<pair<int, int> > G[Maxn];
int done[Maxn];
long long sta[Maxn];
int cnt[64][2];
vector<int> V;
vector<long long> gs;
int ty[64];
int pw[64];
int tot;
void up(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
void dfs(int u, int p) {
  done[u] = 1;
  V.push_back(u);
  for (int i = 0; i < 62; i++) cnt[i][sta[u] >> i & 1]++;
  for (pair<int, int> it : G[u]) {
    int v = it.first;
    long long w = ew[it.second];
    if (v == p) continue;
    if (!done[v]) {
      sta[v] = sta[u] ^ w;
      dfs(v, u);
    } else {
      gs.push_back(sta[u] ^ sta[v] ^ w);
    }
  }
}
void gauss(vector<long long> &gs) {
  tot = 0;
  for (int i = 0, j = 0; i < 62; i++) {
    int cs = -1;
    for (int k = j; k < gs.size(); k++) {
      if (gs[k] >> i & 1) {
        cs = k;
        break;
      }
    }
    if (cs == -1) {
      ty[i] = 0;
      continue;
    }
    tot++;
    ty[i] = 1;
    if (cs != -1) swap(gs[cs], gs[j]);
    for (int k = 0; k < gs.size(); k++) {
      if (k == j) continue;
      if (gs[k] >> i & 1) gs[k] ^= gs[j];
    }
    j++;
  }
  for (int i = 0; i < 62; i++) {
    if (ty[i])
      ty[i] = -1;
    else {
      for (int j = 0; j < gs.size(); j++)
        if (gs[j] >> i & 1) ty[i]++;
    }
  }
}
int solve() {
  int n = V.size();
  int ret = 0;
  for (int i = 0; i < 62; i++) {
    if (ty[i]) {
      up(ret, 1LL * n * (n - 1) / 2 % mod * pw[i] % mod * pw[tot - 1] % mod);
    } else {
      int tmp = 1LL * cnt[i][0] * cnt[i][1] % mod;
      up(ret, 1LL * tmp * pw[i] % mod * pw[tot] % mod);
    }
  }
  return ret;
}
int main() {
  pw[0] = 1;
  for (int i = 1; i < 62; i++) pw[i] = 1LL * pw[i - 1] * 2 % mod;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lld", eu + i, ev + i, ew + i);
    G[eu[i]].push_back(pair<int, int>(ev[i], i));
    G[ev[i]].push_back(pair<int, int>(eu[i], i));
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!done[i]) {
      V.clear();
      gs.clear();
      memset(cnt, 0, sizeof cnt);
      dfs(i, 0);
      gauss(gs);
      up(ans, solve());
    }
  }
  printf("%d\n", ans);
  return 0;
}
