#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 100;
const int M = 200000 + 100;
const long long mod = 1e9 + 7;
struct Edge {
  int v;
  long long w;
  int next;
};
int tot;
int head[N];
bool vis[N];
long long dp[N];
Edge edge[M * 2];
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
  memset(vis, false, sizeof(vis));
  memset(dp, 0, sizeof(dp));
}
void add_edge(int u, int v, long long w) {
  edge[tot].v = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
int n, m;
long long r;
long long P[70];
long long cnt[10];
vector<int> cur;
vector<long long> circle;
long long _pow(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) {
      ret = (ret * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ret;
}
void dfs(int u) {
  vis[u] = true;
  cur.push_back(u);
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].v;
    long long w = edge[i].w;
    if (vis[v]) {
      circle.push_back(dp[u] ^ w ^ dp[v]);
    } else {
      dp[v] = dp[u] ^ w;
      dfs(v);
    }
  }
}
void build() {
  memset(P, 0, sizeof(P));
  r = 0;
  for (int i = 0; i < circle.size(); i++) {
    for (int j = 62; j >= 0; j--) {
      if ((circle[i] >> j) & 1) {
        if (P[j]) {
          circle[i] ^= P[j];
        } else {
          P[j] = circle[i];
          break;
        }
      }
    }
  }
  for (int i = 62; i >= 0; i--) {
    if (P[i]) {
      r++;
    }
  }
}
long long calc() {
  build();
  long long ret = 0;
  long long now;
  for (int i = 0; i <= 62; i++) {
    memset(cnt, 0, sizeof(cnt));
    bool flag = false;
    for (int j = 0; j <= 62; j++) {
      if ((P[j] >> i) & 1) {
        flag = true;
        break;
      }
    }
    for (int j = 0; j < cur.size(); j++) {
      cnt[(dp[cur[j]] >> i) & 1]++;
    }
    now = (cnt[0] * (cnt[0] - 1) / 2) % mod + (cnt[1] * (cnt[1] - 1) / 2) % mod;
    now %= mod;
    if (flag) {
      now *= _pow(2LL, r - 1);
      now %= mod;
      now *= _pow(2LL, (long long)i);
      now %= mod;
      ret += now;
      ret %= mod;
    }
    now = (cnt[0] * cnt[1]) % mod;
    if (flag) {
      now *= _pow(2LL, r - 1);
      now %= mod;
    } else {
      now *= _pow(2LL, r);
      now %= mod;
    }
    now = now * _pow(2LL, i) % mod;
    ret += now;
    ret %= mod;
  }
  return ret;
}
void solve() {
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    cur.clear();
    circle.clear();
    dfs(i);
    ans += calc();
    ans %= mod;
  }
  printf("%lld\n", ans);
}
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    long long w;
    scanf("%d%d%lld", &u, &v, &w);
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  solve();
  return 0;
}
