#include <bits/stdc++.h>
using namespace std;
int n, m, number, first[200009], top, sta[200009], cir_cnt, r, ans;
long long dis[200009], p[70], cir[400009], bit[400009 << 1], cnt[2];
bool vis[200009];
struct edge {
  int to, next;
  long long val;
  void add(int x, int y, long long z) {
    to = y, next = first[x], first[x] = number, val = z;
  }
} e[400009 << 1];
int read() {
  int x = 1;
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') x = -1;
  int s = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - 48;
  return s * x;
}
long long Read() {
  long long x = 1;
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') x = -1;
  long long s = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - 48;
  return s * x;
}
void dfs(int x, int fa, long long now) {
  if (!vis[x])
    dis[x] = now;
  else {
    cir[++cir_cnt] = now ^ dis[x];
    return;
  }
  vis[x] = 1, dis[x] = now, sta[++top] = x;
  for (int i = first[x]; i; i = e[i].next)
    if (e[i].to != fa) dfs(e[i].to, x, now ^ e[i].val);
}
void build() {
  memset(p, 0, sizeof(p));
  r = 0;
  for (int i = 1; i <= cir_cnt; i++) {
    for (int j = 62; j >= 0; j--) {
      if (!(cir[i] >> j)) continue;
      if (!p[j]) {
        p[j] = cir[i];
        break;
      }
      cir[i] ^= p[j];
    }
  }
  for (int j = 0; j <= 62; j++)
    if (p[j] != 0) r++;
}
int get() {
  int ret = 0;
  build();
  for (int i = 0; i <= 62; i++) {
    cnt[0] = cnt[1] = 0;
    bool flag = false;
    for (int j = 0; j <= 62; j++)
      if ((p[j] >> i) & 1) {
        flag = true;
        break;
      }
    for (int j = 1; j <= top; j++) cnt[(dis[sta[j]] >> i) & 1]++;
    int now = ((long long)cnt[0] * (cnt[0] - 1) / 2 +
               (long long)cnt[1] * (cnt[1] - 1) / 2) %
              1000000007;
    if (flag) {
      if (r >= 1) now = (long long)now * bit[r - 1] % 1000000007;
      now = (long long)now * bit[i] % 1000000007;
      ret = (ret + now) % 1000000007;
    }
    now = (long long)cnt[0] * cnt[1] % 1000000007;
    if (flag) {
      if (r >= 1) now = (long long)now * bit[r - 1] % 1000000007;
    } else
      now = (long long)now * bit[r] % 1000000007;
    now = (long long)now * bit[i] % 1000000007;
    ret = (ret + now) % 1000000007;
  }
  return ret;
}
void work() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    long long z = Read();
    e[++number].add(x, y, z), e[++number].add(y, x, z);
  }
  bit[0] = 1;
  for (int i = 1; i <= max(n, m) * 2; i++)
    bit[i] = bit[i - 1] * 2, bit[i] %= 1000000007;
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    top = cir_cnt = 0;
    dfs(i, 0, 0);
    ans = (ans + get()) % 1000000007;
  }
  printf("%d\n", ans);
}
int main() {
  work();
  return 0;
}
