#include <bits/stdc++.h>
int n, m;
struct edge {
  int to;
  long long len;
  edge* next;
} E[4000010], *ne = E, *first[1000010];
void link(int a, int b, long long c) {
  *ne = (edge){b, c, first[a]};
  first[a] = ne++;
}
long long d[1000010], a[2000010], list[2000010];
int dep[1000010], acnt, siz, llen;
bool vis[1000010];
void dfs(int i) {
  vis[i] = 1;
  siz++;
  list[llen++] = d[i];
  for (edge* e = first[i]; e; e = e->next) {
    if (!vis[e->to]) {
      d[e->to] = d[i] ^ e->len;
      dep[e->to] = dep[i] + 1;
      dfs(e->to);
    } else if (dep[e->to] < dep[i] - 1)
      a[acnt++] = d[i] ^ d[e->to] ^ e->len;
  }
}
int pow2[2000010];
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  long long t;
  for (int i = 0; i < m; i++)
    scanf("%d%d%I64d", &u, &v, &t), link(u, v, t), link(v, u, t);
  for (int i = pow2[0] = 1; i <= m || i <= 60; i++)
    pow2[i] = (pow2[i - 1] << 1) % 1000000007;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      acnt = 0;
      siz = 0;
      llen = 0;
      dfs(i);
      int r = 0;
      long long orr = 0;
      if (acnt) {
        for (int j = 59; j >= 0; j--) {
          int mp = r;
          for (int k = r + 1; k < acnt; k++)
            if (a[k] > a[mp]) mp = k;
          if (!a[mp]) break;
          t = a[mp];
          a[mp] = a[r];
          a[r] = t;
          for (int k = r + 1; k < acnt; k++)
            if ((a[k] ^ t) < a[k]) a[k] ^= t;
          r++;
        }
      }
      for (int k = 0; k < r; k++) orr |= a[k];
      for (int j = 0; j < 60; j++) {
        if (orr >> j & 1)
          ans = (ans + 1ll * siz * (siz - 1) / 2 % 1000000007 * pow2[r - 1] %
                           1000000007 * pow2[j]) %
                1000000007;
        else {
          int cnt0 = 0, cnt1 = 0;
          for (int k = 0; k < llen; k++)
            if (list[k] >> j & 1)
              cnt1++;
            else
              cnt0++;
          ans = (ans + 1ll * cnt0 * cnt1 % 1000000007 * pow2[r] % 1000000007 *
                           pow2[j]) %
                1000000007;
        }
      }
    }
  printf("%d", ans);
}
