#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
const int N = 1e5 + 5, K = 4, M = 380;
const double PI = acos(-1);
mt19937 rng(time(0));
struct E {
  int to, w;
};
unordered_map<int, int> mp;
vector<E> g[N];
int n, m, x, y, w, tot;
int val[N], feat[N], cmb[M][M], f[M], f1[M];
char vis[N], conn[N];
array<int, 6> a;
void insert(array<int, 6> &a, int num) {
  int ii = -1;
  for (int i = (K); i >= (0); --i)
    if (num >> i & 1) {
      if (a[i])
        num ^= a[i];
      else {
        for (int j = (i - 1); j >= (0); --j)
          if (num >> j & 1) num ^= a[j];
        for (int j = (i + 1); j <= (K); ++j)
          if (a[j] >> i & 1) a[j] ^= num;
        a[i] = num;
        return;
      }
    }
  a[K + 1] = -1;
}
void dfs(int x, int fa, int num) {
  val[x] = num, vis[x] = 1;
  for (auto ele : g[x]) {
    int u = ele.to, w = ele.w;
    if (conn[u]) continue;
    if (!vis[u])
      dfs(u, x, num ^ w);
    else if (u != fa && vis[u] == 2)
      insert(a, w ^ val[u] ^ val[x]);
  }
  vis[x] = 2;
}
int calc(array<int, 6> a) {
  if (a[K + 1] == -1) return -1;
  int res = 0;
  for (int i = (0); i <= (K); ++i) res = (res << i + 1) + a[i];
  return res;
}
void precalc() {
  array<int, 6> Q[M];
  Q[tot = 1].fill(0);
  mp[0] = 1, mp[-1] = 0;
  for (int i = (1); i <= (tot); ++i) {
    array<int, 6> x = Q[i], y;
    for (int j = (1); j <= (31); ++j) {
      y = x, insert(y, j);
      int key = calc(y);
      if (!mp.count(key)) {
        ++tot, mp[key] = tot, Q[tot] = y;
      }
    }
  }
  for (int i = (1); i <= (tot); ++i)
    for (int j = (1); j <= (i); ++j) {
      array<int, 6> x = Q[i], y = Q[j];
      for (int u = (0); u <= (K); ++u)
        if (y[u]) insert(x, y[u]);
      cmb[i][j] = cmb[j][i] = mp[calc(x)];
    }
}
void add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
int main() {
  precalc();
  memset(conn, 0, sizeof conn);
  conn[1] = true;
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i) {
    scanf("%d%d%d", &x, &y, &w);
    if (x > y) swap(x, y);
    g[x].push_back({y, w});
    g[y].push_back({x, w});
    if (x == 1) conn[y] = true;
  }
  memset(vis, 0, sizeof vis);
  for (auto ele : g[1]) {
    int x = ele.to;
    a = {0, 0, 0, 0, 0, 0};
    dfs(x, 1, ele.w);
    feat[x] = mp[calc(a)];
  }
  memset(vis, 0, sizeof vis);
  f[1] = 1;
  for (auto ele : g[1]) {
    int x = ele.to;
    if (vis[x]) continue;
    vis[x] = true;
    int cyc = 0, w = 0, h = feat[x];
    for (auto e2 : g[x]) {
      int y = e2.to;
      if (!conn[y] || vis[y] || y == 1) continue;
      vis[y] = true, cyc = y, w = e2.w;
      break;
    }
    if (cyc) h = cmb[h][feat[cyc]];
    if (!h) continue;
    memcpy(f1, f, sizeof f1);
    for (int i = (1); i <= (tot); ++i) add(f1[cmb[i][h]], f[i]);
    if (cyc) {
      for (int i = (1); i <= (tot); ++i) add(f1[cmb[i][h]], f[i]);
      array<int, 6> tmp{};
      insert(tmp, val[x] ^ val[cyc] ^ w);
      h = cmb[h][mp[calc(tmp)]];
      if (h)
        for (int i = (1); i <= (tot); ++i) add(f1[cmb[i][h]], f[i]);
    }
    swap(f, f1);
  }
  int ans = 0;
  for (int i = (1); i <= (tot); ++i) add(ans, f[i]);
  printf("%d\n", ans);
  return 0;
}
