#include <bits/stdc++.h>
int *ej[100000], eo[100000];
long long *ew[100000];
void append(int i, int j, long long w) {
  int o = eo[i]++;
  if (o >= 2 && (o & o - 1) == 0) {
    ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]);
    ew[i] = (long long *)realloc(ew[i], o * 2 * sizeof *ew[i]);
  }
  ej[i][o] = j, ew[i][o] = w;
}
long long bb[60], b_;
int sz;
void add(long long b) {
  int l;
  b_ |= b;
  for (l = 0; l < 60; l++)
    if (b & 1LL << l) {
      if (bb[l] & 1LL << l)
        b ^= bb[l];
      else {
        bb[l] = b, sz++;
        return;
      }
    }
}
long long xx[100000];
char visited[100000];
int kk[60], cnt;
void dfs(int p, int i, long long x) {
  int o, l;
  if (visited[i]) {
    add(xx[i] ^ x);
    return;
  }
  xx[i] = x, visited[i] = 1, cnt++;
  for (l = 0; l < 60; l++)
    if (x & 1LL << l) kk[l]++;
  for (o = eo[i]; o--;) {
    int j = ej[i][o];
    long long w = ew[i][o];
    if (j != p) dfs(i, j, x ^ w);
  }
}
int main() {
  int n, m, i, j, ans;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    ej[i] = (int *)malloc(2 * sizeof *ej[i]);
    ew[i] = (long long *)malloc(2 * sizeof *ew[i]);
  }
  while (m--) {
    long long w;
    scanf("%d%d%lld", &i, &j, &w), i--, j--;
    append(i, j, w), append(j, i, w);
  }
  ans = 0;
  for (i = 0; i < n; i++)
    if (!visited[i]) {
      int l, p;
      memset(bb, 0, 60 * sizeof *bb), b_ = 0, sz = 0;
      memset(kk, 0, 60 * sizeof *kk);
      cnt = 0;
      dfs(-1, i, 0);
      p = 1;
      for (l = 0; l < 60; l++) {
        int k;
        if (b_ & 1LL << l)
          k = (long long)cnt * (cnt - 1) / 2 % 1000000007 *
              ((1LL << sz - 1) % 1000000007) % 1000000007;
        else
          k = (long long)kk[l] * (cnt - kk[l]) % 1000000007 *
              ((1LL << sz) % 1000000007) % 1000000007;
        ans = (ans + (long long)k * p) % 1000000007;
        p = p * 2 % 1000000007;
      }
    }
  printf("%d\n", ans);
  return 0;
}
