#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const int N = 2e5 + 100;
struct Front_Star {
  int u, v, nxt;
  long long w;
} e[N << 2];
int cnt = 0;
int first[N];
void add(int u, int v, long long w) {
  ++cnt;
  e[cnt].u = u;
  e[cnt].v = v;
  e[cnt].w = w;
  e[cnt].nxt = first[u];
  first[u] = cnt;
}
struct LB {
  long long a[62];
  long long tmp[62];
  int cnt;
  void Clr() {
    memset(a, 0, sizeof(a));
    memset(tmp, 0, sizeof(tmp));
    cnt = 0;
  }
  void Insert(long long x) {
    for (int i = 60; i >= 0; --i) {
      if (x & (1LL << i)) {
        if (!a[i]) {
          a[i] = x;
          break;
        }
        x ^= a[i];
      }
    }
  }
  void ReBuild() {
    for (int i = 60; i >= 0; --i) {
      for (int j = i - 1; j >= 0; --j) {
        if (a[i] & (1LL << j)) a[i] ^= a[j];
      }
    }
    cnt = 0;
    for (int i = 0; i <= 60; ++i)
      if (a[i]) tmp[cnt++] = a[i];
    memset(a, 0, sizeof(a));
    for (int i = 0; i < cnt; ++i) a[i] = tmp[i];
  }
} Ans;
long long pow2[N];
int Tim = 0;
int vis[N];
long long val[N];
int S[N];
int top = 0;
void DFS(int u, long long v) {
  val[u] = v;
  vis[u] = Tim;
  S[++top] = u;
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v]) {
      Ans.Insert(val[u] ^ val[v] ^ e[i].w);
    } else {
      DFS(v, val[u] ^ e[i].w);
    }
  }
}
void Clr() {
  top = 0;
  Ans.Clr();
}
long long ans = 0;
void Calc() {
  long long Du[2];
  Ans.ReBuild();
  int r = Ans.cnt;
  for (int i = 0; i <= 60; ++i) {
    Du[0] = Du[1] = 0;
    bool flag = 0;
    for (int j = 1; j <= top; ++j) Du[(val[S[j]] >> i) & 1]++;
    for (int j = 0; j < r; ++j)
      if (Ans.a[j] & (1LL << i)) flag = 1;
    long long now =
        (Du[0] * (Du[0] - 1) / 2 % mod + Du[1] * (Du[1] - 1) / 2 % mod) % mod;
    if (flag) {
      now = now * pow2[r - 1] % mod;
      now = now * pow2[i] % mod;
      ans = (ans + now) % mod;
    }
    now = (Du[0] * Du[1]) % mod;
    if (flag) {
      now = now * pow2[r - 1] % mod;
    } else {
      now = now * pow2[r] % mod;
    }
    now = now * pow2[i] % mod;
    ans = (ans + now) % mod;
  }
}
int n, m;
int main() {
  pow2[0] = 1;
  for (int i = 1; i <= 60; ++i) pow2[i] = pow2[i - 1] * 2LL % mod;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    long long w;
    scanf("%d%d%lld", &u, &v, &w);
    add(u, v, w);
    add(v, u, w);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      ++Tim;
      Clr();
      DFS(i, 0);
      Calc();
    }
  }
  cout << ans;
  return 0;
}
