#include <bits/stdc++.h>
using namespace std;
const int MX = 5e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Edge {
  long long val;
  int v, nxt;
} E[MX];
int Head[MX], erear;
void edge_init() {
  erear = 0;
  memset(Head, -1, sizeof(Head));
}
void edge_add(int u, int v, long long val) {
  E[erear].v = v;
  E[erear].val = val;
  E[erear].nxt = Head[u];
  Head[u] = erear++;
}
int n, m, sz, r;
long long A[MX], P[62], dis[MX];
vector<int> path;
long long power(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, long long s) {
  if (dis[u] == -1) {
    dis[u] = s;
  } else {
    A[++sz] = dis[u] ^ s;
    return;
  }
  path.push_back(u);
  for (int i = Head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    DFS(v, s ^ E[i].val);
  }
}
void Guass_base() {
  memset(P, 0, sizeof(P));
  for (int i = 1; i <= sz; i++) {
    for (int j = 62; j >= 0; j--) {
      if (!(A[i] >> j & 1)) continue;
      if (!P[j]) {
        P[j] = A[i];
        break;
      }
      A[i] ^= P[j];
    }
  }
  r = 0;
  for (int i = 62; i >= 0; i--) {
    if (P[i]) r++;
  }
}
long long solve() {
  Guass_base();
  long long ans = 0;
  for (int i = 62; i >= 0; i--) {
    int cnt[2] = {0}, sign = 0;
    for (int j = 62; j >= 0; j--) {
      if (P[j] >> i & 1) sign = 1;
    }
    for (int j = 0; j < path.size(); j++) {
      int u = path[j];
      if (sign)
        ans += power(2, i + r - 1) * j % mod;
      else
        ans += power(2, i + r) * cnt[!(dis[u] >> i & 1)] % mod;
      ans %= mod;
      cnt[dis[u] >> i & 1]++;
    }
  }
  return ans;
}
int main() {
  edge_init();
  scanf("%d%d", &n, &m);
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long val;
    scanf("%d%d%I64d", &u, &v, &val);
    edge_add(u, v, val);
    edge_add(v, u, val);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dis[i] == -1) {
      path.clear();
      sz = 0;
      DFS(i, 0);
      ans += solve();
      ans %= mod;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
