#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long as = 0, fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    as = as * 10 + c - '0';
    c = getchar();
  }
  return as * fu;
}
const int N = 200005;
const long long mod = 1000000007;
inline long long sum(long long x, long long y) {
  return x + y >= mod ? x + y - mod : x + y;
}
inline long long mlt(long long x, long long y) { return x * 1ll * y % mod; }
inline long long f(long long x) { return x * 1ll * (x - 1) / 2ll % mod; }
long long head[N], nxt[N << 1], tp[N << 1], cnt;
long long cst[N << 1];
void _add(long long x, long long y, long long w) {
  nxt[++cnt] = head[x], head[x] = cnt;
  tp[cnt] = y, cst[cnt] = w;
}
void add(long long x, long long y) {
  long long w = read();
  _add(x, y, w), _add(y, x, w);
}
long long p[65], sze;
bool Ins(long long x) {
  for (long long j = 63; j >= 0; --j)
    if ((x >> j) & 1) {
      if (p[j])
        x ^= p[j];
      else {
        p[j] = x;
        return 1;
      }
    }
  return 0;
}
long long stk[N];
long long dis[N];
bool vis[N];
void dfs(long long x, long long f) {
  vis[x] = 1, stk[++stk[0]] = x;
  for (long long i = head[x]; i; i = nxt[i]) {
    long long sn = tp[i];
    if (vis[sn])
      sze += Ins(dis[x] ^ dis[sn] ^ cst[i]);
    else {
      dis[sn] = dis[x] ^ cst[i];
      dfs(sn, x);
    }
  }
}
long long num[2];
long long solve() {
  long long res = 0, tmp;
  for (long long k = 0; k <= 63; ++k) {
    bool flag = 0;
    for (long long j = 0; j <= 63; ++j)
      if ((p[j] >> k) & 1) flag = 1;
    num[0] = num[1] = 0;
    for (long long i = 1; i <= stk[0]; ++i) num[(dis[stk[i]] >> k) & 1]++;
    tmp = sum(f(num[0]), f(num[1]));
    if (flag) {
      tmp = mlt(tmp, (1ll << sze - 1) % mod);
      tmp = mlt(tmp, (1ll << k) % mod);
      res = sum(res, tmp);
    }
    tmp = mlt(num[0], num[1]);
    if (flag)
      tmp = mlt(tmp, (1ll << sze - 1) % mod);
    else
      tmp = mlt(tmp, (1ll << sze) % mod);
    tmp = mlt(tmp, (1ll << k) % mod);
    res = sum(res, tmp);
  }
  return res;
}
long long n, m, ans;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; ++i) add(read(), read());
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      stk[0] = dis[i] = 0;
      sze = 0, memset(p, 0, sizeof p);
      dfs(i, i);
      ans = sum(ans, solve());
    }
  cout << ans << endl;
  return 0;
}
