#include <bits/stdc++.h>
using namespace std;
struct ii {
  int x, y;
  ii(int x = 0, int y = 0) : x(x), y(y) {}
  bool operator<(const ii &a) const {
    if (x != a.x) return x < a.x;
    return y < a.y;
  }
  bool operator==(const ii &a) const { return x == a.x && y == a.y; }
  ii friend operator+(ii a, ii b) { return ii(a.x + b.x, a.y + b.y); }
  ii friend operator-(ii a, ii b) { return ii(a.x - b.x, a.y - b.y); }
};
template <class T>
void sc(T &x) {
  x = 0;
  char c;
  int f = 1;
  while (c = getchar(), c < 48)
    if (c == '-') f = -1;
  do x = x * 10 + (c ^ 48);
  while (c = getchar(), c > 47);
  x *= f;
}
template <class T>
void nt(T x) {
  if (!x) return;
  nt(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
void pt(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x)
    putchar('0');
  else
    nt(x);
}
template <class T>
void pts(T x) {
  pt(x);
  putchar(' ');
}
template <class T>
void ptn(T x) {
  pt(x);
  putchar('\n');
}
template <class v>
void pp(v x, int y) {
  static char ch[] = {" \n"};
  pt(x);
  putchar(ch[y]);
}
template <class T>
void PP(T *x, int y) {
  for (int i = 0, i_ = y; i < i_; ++i) pp(x[i], i == y - 1);
}
template <class T>
void Max(T &x, T y) {
  if (x < y) x = y;
}
template <class T>
void Min(T &x, T y) {
  if (x > y) x = y;
}
const int maxn = 100005;
const int maxm = 400005;
const int mod = 1e9 + 7;
typedef int arrn[maxn];
typedef int arrm[maxm];
int n, m;
arrm point, nextp;
long long aval[maxm];
arrn head;
int ecnt;
void ins(int u, int v, long long w) {
  point[++ecnt] = v;
  nextp[ecnt] = head[u];
  aval[ecnt] = w;
  head[u] = ecnt;
}
bool vis[maxn], inq[maxn];
long long v[maxn];
long long d[maxm], tot;
long long bin[maxm];
int s[maxn], cnt;
void dfs(int x) {
  inq[x] = vis[x] = true;
  s[cnt++] = x;
  for (int i = head[x]; i; i = nextp[i]) {
    int to = point[i];
    if (inq[to]) {
      long long vv = v[to] ^ v[x] ^ aval[i];
      if (vv) d[tot++] = vv;
    } else if (!vis[to]) {
      v[to] = v[x] ^ aval[i];
      dfs(to);
    }
  }
  inq[x] = 0;
}
void cal() {
  int tt = 0;
  for (long long i = 1LL << 62; i; i >>= 1) {
    bool ok = 0;
    for (int k = tt, k_ = tot; k < k_; ++k)
      if (d[k] & i) {
        swap(d[tt], d[k]);
        ok = 1;
        break;
      }
    if (!ok) continue;
    for (int k = 0, k_ = tot; k < k_; ++k)
      if (k != tt && (d[k] & i)) d[k] ^= d[tt];
    tt++;
  }
  tot = tt;
}
int main() {
  sc(n);
  sc(m);
  bin[0] = 1;
  for (int i = 1, i_ = max(n, m) + 1; i < i_; ++i)
    bin[i] = bin[i - 1] * 2 % mod;
  for (int i = 0, i_ = m; i < i_; ++i) {
    int u, v;
    long long w;
    sc(u);
    sc(v);
    sc(w);
    ins(u, v, w);
    ins(v, u, w);
  }
  long long ans = 0;
  for (int i = 1, i_ = n + 1; i < i_; ++i)
    if (!vis[i]) {
      tot = 0;
      cnt = 0;
      dfs(i);
      cal();
      for (int pos = 0, pos_ = 62; pos < pos_; ++pos) {
        long long A[2] = {0};
        for (int i = 0, i_ = cnt; i < i_; ++i) A[v[s[i]] >> pos & 1]++;
        bool ok = 0;
        for (int i = 0, i_ = tot; i < i_; ++i)
          if (d[i] >> pos & 1) ok = 1;
        long long res = 0, tmp, k;
        {
          tmp = (A[0] * (A[0] - 1) + A[1] * (A[1] - 1)) / 2 % mod;
          if (ok)
            k = bin[tot - 1];
          else
            k = 0;
          res = tmp * k % mod;
        }
        {
          tmp = A[0] * A[1] % mod;
          if (ok)
            k = bin[tot - 1];
          else
            k = bin[tot];
          res = (res + tmp * k) % mod;
        }
        ans = (ans + res * bin[pos]) % mod;
      }
    }
  ptn(ans);
  return 0;
}
