#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
const int N = 100005;
struct edge {
  int to, next;
  long long v;
};
edge e[N * 4];
int head[N], tot;
int vis[N], q[N], ans, n, m;
long long tag[N], a[65], sum, s;
void insert(long long x) {
  if (!x) return;
  sum |= x;
  for (int i = (int)(59); i >= (int)(0); i--)
    if (x & (1ll << i))
      if (!a[i])
        a[i] = x, x = 0, s++;
      else
        x ^= a[i];
}
void add(int x, int y, long long v) {
  e[++tot] = (edge){y, head[x], v};
  head[x] = tot;
}
int power(int x, int y) {
  int s = 1;
  for (; y; y /= 2, x = 1ll * x * x % mo)
    if (y & 1) s = 1ll * s * x % mo;
  return s;
}
void dfs(int x, int fa) {
  q[++*q] = x;
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) {
      if (!vis[e[i].to]) {
        tag[e[i].to] = tag[x] ^ e[i].v;
        dfs(e[i].to, x);
      } else
        insert(tag[x] ^ tag[e[i].to] ^ e[i].v);
    }
}
void solve(int x) {
  memset(a, 0, sizeof(a));
  *q = sum = s = 0;
  dfs(x, 0);
  static int cnt[65][2];
  memset(cnt, 0, sizeof(cnt));
  for (int i = (int)(1); i <= (int)(*q); i++)
    for (int j = (int)(0); j <= (int)(59); j++) cnt[j][(tag[q[i]] >> j) & 1]++;
  for (int i = (int)(0); i <= (int)(59); i++) {
    int ss = 0;
    if (sum & (1ll << i))
      ss = 1ll * (*q) * ((*q) - 1) % mo * (mo + 1) / 4 % mo;
    else
      ss = 1ll * cnt[i][0] * cnt[i][1] % mo;
    ans = (ans + 1ll * power(2, s) * ss % mo * ((1ll << i) % mo)) % mo;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(m); i++) {
    int x, y;
    long long v;
    scanf("%d%d%lld", &x, &y, &v);
    add(x, y, v);
    add(y, x, v);
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    if (!vis[i]) solve(i);
  printf("%d\n", ans);
}
