#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int head[200086], q[200086 * 2], nxt[200086 * 2], tt;
long long dt[200086 * 2], pw[200086];
long long dis[200086], a[70];
bool vis[200086];
long long num[70][2];
long long cnt;
void ins(int u, int v, long long w) {
  q[++tt] = v;
  nxt[tt] = head[u];
  head[u] = tt;
  dt[tt] = w;
}
void dfs(int i, int pre) {
  vis[i] = 1;
  for (int k = 0; k <= 62; k++) {
    int dd = (((long long)1 << (long long)k) & dis[i]) > 0;
    num[k][dd]++;
  }
  for (int j = head[i]; j; j = nxt[j])
    if (q[j] != pre)
      if (vis[q[j]]) {
        long long w = dis[q[j]] ^ dt[j] ^ dis[i];
        for (int k = 62; k >= 0; k--) {
          if (!(w >> k)) continue;
          if (!a[k]) {
            a[k] = w;
            cnt++;
            break;
          }
          w ^= a[k];
        }
      } else {
        dis[q[j]] = dis[i] ^ dt[j];
        dfs(q[j], i);
      }
}
void clr() {
  memset(num, 0, sizeof(num));
  cnt = 0;
  memset(a, 0, sizeof(a));
}
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    long long w = read();
    ins(u, v, w);
    ins(v, u, w);
  }
  long long ans = 0;
  pw[0] = 1;
  for (int i = 1; i <= 62; i++) pw[i] = (pw[i - 1] * 2) % 1000000007;
  for (int t = 1; t <= n; t++)
    if (!vis[t]) {
      clr();
      dfs(t, 0);
      if (cnt > 0) {
        for (int i = 0; i <= 62; i++) {
          int flag = 0;
          for (int k = 0; k <= 62; k++)
            if (((a[k] >> i) & 1) > 0) {
              flag = 1;
              break;
            }
          long long sum1 = (num[i][0] * num[i][1]) % 1000000007;
          long long sum2 = ((num[i][0] * (num[i][0] - 1) / 2) % 1000000007 +
                            (num[i][1] * (num[i][1] - 1) / 2) % 1000000007) %
                           1000000007;
          long long w = pw[i] % 1000000007;
          if (flag)
            ans = (ans + ((w * ((sum1 + sum2) % 1000000007)) % 1000000007 *
                          (pw[cnt - 1] % 1000000007)) %
                             1000000007) %
                  1000000007;
          else
            ans = (ans + ((w * sum1) % 1000000007 * (pw[cnt] % 1000000007)) %
                             1000000007) %
                  1000000007;
        }
      } else {
        for (int i = 0; i <= 62; i++) {
          long long sum = (num[i][0] * num[i][1]) % 1000000007;
          long long w = pw[i] % 1000000007;
          ans = (ans + (sum * w) % 1000000007) % 1000000007;
        }
      }
    }
  cout << ans << endl;
  return 0;
}
