#include <bits/stdc++.h>
using namespace std;
long long p2[100010 + 400010];
void init() {
  p2[0] = 1;
  for (int i = 1, ed_i = 300000; i <= ed_i; i++) {
    p2[i] = p2[i - 1] * 2 % 1000000007;
  }
}
int ecnt, ev[400010], pe[400010], le[100010];
long long ew[400010];
void addEdge(int u, int v, long long w) {
  ecnt++;
  pe[ecnt] = le[u];
  le[u] = ecnt;
  ev[ecnt] = v;
  ew[ecnt] = w;
}
vector<long long> v;
int getRank() {
  int rk = 0;
  for (int i = 0; i < 60; i++) {
    int flag = 0;
    for (int j = rk; j < v.size(); j++)
      if ((v[j] >> i) & 1) {
        swap(v[j], v[rk]);
        flag = 1;
        break;
      }
    if (!flag) continue;
    for (int j = rk + 1; j < v.size(); j++)
      if ((v[j] >> i) & 1) v[j] ^= v[rk];
    rk++;
  }
  return rk;
}
int nn;
int vis[100010], cnt[100][2];
long long path[100010];
void dfs(int u, int fa) {
  nn++;
  vis[u] = 1;
  for (int i = 0, ed_i = 60; i < ed_i; i++) {
    cnt[i][(path[u] >> i) & 1]++;
  }
  for (int i = le[u]; i; i = pe[i]) {
    int &v = ev[i];
    long long &w = ew[i];
    if (v == fa) continue;
    if (!vis[v]) {
      path[v] = path[u] ^ w;
      dfs(v, u);
    } else {
      ::v.push_back(path[u] ^ path[v] ^ w);
    }
  }
}
int main() {
  init();
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1, ed_i = m; i <= ed_i; i++) {
    int u, v;
    long long w;
    scanf("%d%d%I64d", &u, &v, &w);
    addEdge(u, v, w);
    addEdge(v, u, w);
  }
  long long ans = 0;
  for (int i = 1, ed_i = n; i <= ed_i; i++) {
    if (!vis[i]) {
      memset(cnt, 0, sizeof(cnt));
      nn = 0;
      v.clear();
      dfs(i, 0);
      int rk = getRank();
      for (int j = 0, ed_j = 60; j < ed_j; j++) {
        int flag = 0;
        for (int k = 0, ed_k = rk; k < ed_k; k++) {
          if ((v[k] >> j) & 1) flag = 1;
        }
        if (flag) {
          ans += p2[rk + j - 1] * (nn * (long long)(nn - 1) / 2 % 1000000007) %
                 1000000007;
          ans %= 1000000007;
        } else {
          ans += p2[rk + j] * (cnt[j][0] * (long long)cnt[j][1] % 1000000007) %
                 1000000007;
          ans %= 1000000007;
        }
      }
    }
  }
  printf("%I64d", ans);
  return 0;
}
