#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 15;
const int maxe = 4e5 + 15;
const int mod = 1e9 + 7;
int n, m;
struct edge {
  int to, nxt;
  long long len;
} e[maxe];
int head[maxn];
int tot;
void adde(int u, int v, long long l) {
  e[tot].to = v;
  e[tot].len = l;
  e[tot].nxt = head[u];
  head[u] = tot++;
}
long long dis[maxn];
long long cir[maxe];
int cirtot;
bool vis[maxn];
vector<int> vec;
void init() {
  vec.clear();
  cirtot = 0;
}
void dfs(int u) {
  vec.push_back(u);
  vis[u] = 1;
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].to;
    long long len = e[i].len;
    if (vis[v]) {
      if (dis[u] ^ dis[v] ^ len != 0) cir[cirtot++] = dis[u] ^ dis[v] ^ len;
    } else {
      dis[v] = dis[u] ^ len;
      dfs(v);
    }
  }
}
long long p[64];
int pnum;
void build() {
  memset(p, 0, sizeof(p));
  pnum = 0;
  for (int i = 0; i < cirtot; i++) {
    long long cnt = cir[i];
    for (int j = 63; j >= 0; j--) {
      if (cnt >> j & 1) {
        if (!p[j]) {
          p[j] = cnt;
          break;
        }
        cnt ^= p[j];
      }
    }
  }
  for (int i = 0; i < 64; i++)
    if (p[i]) pnum++;
}
long long cnt[2];
long long ans;
long long pw2[64];
void calc() {
  for (int w = 0; w < 64; w++) {
    bool f = 0;
    cnt[0] = cnt[1] = 0;
    for (auto v : vec) cnt[dis[v] >> w & 1]++;
    for (int i = 0; i < 64; i++) {
      if (p[i] >> w & 1) {
        f = 1;
        break;
      }
    }
    long long cc = cnt[0] * (cnt[0] - 1) / 2 + cnt[1] * (cnt[1] - 1) / 2;
    cc %= mod;
    if (f) {
      cc = cc * pw2[pnum - 1] % mod * pw2[w] % mod;
      ans = (ans + cc) % mod;
    }
    cc = cnt[0] * cnt[1] % mod;
    if (f)
      cc = cc * pw2[pnum - 1] % mod * pw2[w] % mod;
    else
      cc = cc * pw2[pnum] % mod * pw2[w] % mod;
    ans = (ans + cc) % mod;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  pw2[0] = 1;
  for (int i = 1; i < 64; i++) {
    pw2[i] = pw2[i - 1] * 2 % mod;
  }
  long long a, b, c;
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld%lld", &a, &b, &c);
    adde(a, b, c);
    adde(b, a, c);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    init();
    dfs(i);
    build();
    calc();
  }
  printf("%lld\n", ans);
  return 0;
}
