#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 100005;
int n, m, vis[maxn], tot, head[maxn], cnt[66][2];
long long dis[maxn], base[66];
vector<long long> a;
struct node {
  int v, next;
  long long w;
} g[4 * maxn];
void add_edge(int u, int v, long long w) {
  g[tot].v = v, g[tot].next = head[u], g[tot].w = w, head[u] = tot++;
}
void dfs(int u, long long d) {
  dis[u] = d, vis[u] = 1;
  for (int i = 0; i <= 62; i++) cnt[i][(dis[u] >> i) & 1]++;
  for (int i = head[u]; ~i; i = g[i].next) {
    int v = g[i].v;
    long long w = g[i].w;
    if (vis[v])
      a.push_back(dis[u] ^ dis[v] ^ w);
    else
      dfs(v, dis[u] ^ w);
  }
}
void add(int &x, int y) {
  x = x + y >= 1000000007 ? x + y - 1000000007 : x + y;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  while (m--) {
    int u, v;
    long long w;
    scanf("%d%d%I64d", &u, &v, &w);
    add_edge(u, v, w), add_edge(v, u, w);
  }
  int ans = 0;
  for (int u = 1; u <= n; u++)
    if (!vis[u]) {
      a.clear();
      memset(base, 0, sizeof(base));
      memset(cnt, 0, sizeof(cnt));
      dfs(u, 0);
      for (int i = 0; i < a.size(); i++)
        for (int j = 62; j >= 0; j--)
          if ((a[i] >> j) & 1) {
            if (!base[j]) {
              base[j] = a[i];
              break;
            } else
              a[i] ^= base[j];
          }
      int num = 0;
      for (int i = 0; i <= 62; i++)
        if (base[i]) num++;
      for (int i = 0; i <= 62; i++) {
        int res = 0, x = cnt[i][0], y = cnt[i][1], flag = 0;
        for (int j = 0; j <= 62; j++)
          if ((base[j] >> i) & 1) {
            flag = 1;
            break;
          }
        if (flag) {
          int tx = (long long)x * (x - 1) / 2 % 1000000007,
              ty = (long long)y * (y - 1) / 2 % 1000000007,
              tz = (1ll << (num - 1)) % 1000000007;
          add(res, (long long)(tx + ty) % 1000000007 * tz % 1000000007);
          add(res, (long long)x * y % 1000000007 * tz % 1000000007);
        } else {
          int tz = (1ll << num) % 1000000007;
          add(res, (long long)x * y % 1000000007 * tz % 1000000007);
        }
        add(ans, (long long)(1ll << i) % 1000000007 * res % 1000000007);
      }
    }
  printf("%d\n", ans);
  return 0;
}
