#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 100005, ZT = 500, K = 5, mod = 1e9 + 7;
struct data {
  int a[K];
  bool ins(int x) {
    for (int i = (int)(K - 1); i >= (int)(0); i--)
      if (x >> i & 1) {
        if (a[i]) {
          x ^= a[i];
        } else {
          for (int j = (int)(0); j <= (int)(i - 1); j++)
            if (x >> j & 1) x ^= a[j];
          a[i] = x;
          for (int j = (int)(i + 1); j <= (int)(K - 1); j++)
            if (a[j] >> i & 1) a[j] ^= x;
          return 1;
        }
      }
    return 0;
  }
  int& operator[](int x) { return a[x]; }
} A[ZT], ffff, qj;
bool operator<(data a, data b) {
  for (int i = (int)(0); i <= (int)(K - 1); i++)
    if (a[i] != b[i]) return a[i] < b[i];
  return 0;
}
map<data, int> M;
vector<pair<int, int> > v[N];
bool vis[N], bj[N];
int dis[N], alb[N], fa[N], Q, QJ, QQ;
void dfs(int p) {
  vis[p] = 1;
  for (auto i : v[p])
    if (i.first != 1) {
      if (!vis[i.first]) {
        dis[i.first] = dis[p] ^ i.second;
        fa[i.first] = p;
        dfs(i.first);
      } else {
        if (bj[p] && bj[i.first]) {
          Q = 1;
          QQ = alb[p] ^ alb[i.first] ^ i.second;
        } else if (i.first != fa[p] && i.first < p) {
          QJ *= qj.ins(i.second ^ dis[p] ^ dis[i.first]);
        }
      }
    }
}
int dq, gg[ZT][ZT], zy[ZT][ZT];
long long ans, f[ZT], g[ZT];
inline void add(long long& a, long long b) { a = (a + b) % mod; }
void dfs(data a) {
  if (!M.count(a)) {
    M[a] = ++dq;
    A[dq] = a;
  } else
    return;
  for (int j = (int)(0); j <= (int)((1 << K) - 1); j++) {
    data b = a;
    b.ins(j);
    dfs(b);
  }
}
int main() {
  dfs(ffff);
  for (int i = (int)(1); i <= (int)(dq); i++)
    for (int j = (int)(1); j <= (int)(dq); j++) {
      data a = A[i];
      gg[i][j] = 1;
      for (int o = (int)(0); o <= (int)(K - 1); o++)
        if (A[j][o]) gg[i][j] &= a.ins(A[j][o]);
      zy[i][j] = M[a];
    }
  int n = read(), m = read();
  for (int i = (int)(1); i <= (int)(m); i++) {
    int a = read(), b = read(), w = read();
    v[a].push_back(make_pair(b, w));
    v[b].push_back(make_pair(a, w));
  }
  for (auto i : v[1]) {
    bj[i.first] = 1;
    alb[i.first] = i.second;
  }
  vis[1] = 1;
  f[1] = 1;
  for (auto i : v[1])
    if (!vis[i.first]) {
      Q = 0;
      QJ = 1;
      memset((qj.a), 0, sizeof(qj.a));
      dfs(i.first);
      if (!QJ) continue;
      memcpy(g, f, sizeof(f));
      if (Q) {
        int x = M[qj];
        QJ *= qj.ins(QQ);
        int y = M[qj];
        for (int j = (int)(1); j <= (int)(dq); j++) {
          if (gg[j][x]) add(g[zy[j][x]], f[j] * 2);
          if (gg[j][y]) add(g[zy[j][y]], f[j] * QJ);
        }
      } else {
        int x = M[qj];
        for (int j = (int)(1); j <= (int)(dq); j++)
          if (gg[j][x]) add(g[zy[j][x]], f[j]);
      }
      swap(f, g);
    }
  for (int i = (int)(1); i <= (int)(dq); i++) add(ans, f[i]);
  cout << ans << endl;
}
