You are given an undirected graph, constisting of n vertices and m edges. Each edge of the graph has some non-negative integer written on it.

Let's call a triple (u, v, s) interesting, if 1 ≤ u < v ≤ n and there is a path (possibly non-simple, i.e. it can visit the same vertices and edges multiple times) between vertices u and v such that xor of all numbers written on the edges of this path is equal to s. When we compute the value s for some path, each edge is counted in xor as many times, as it appear on this path. It's not hard to prove that there are finite number of such triples.

Calculate the sum over modulo 109 + 7 of the values of s over all interesting triples.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 0 ≤ m ≤ 200 000) — numbers of vertices and edges in the given graph.

The follow m lines contain three integers ui, vi and ti (1 ≤ ui, vi ≤ n, 0 ≤ ti ≤ 1018, ui ≠ vi) — vertices connected by the edge and integer written on it. It is guaranteed that graph doesn't contain self-loops and multiple edges.

Output

Print the single integer, equal to the described sum over modulo 109 + 7.

Examples

Input

4 4
1 2 1
1 3 2
2 3 3
3 4 1


Output

12


Input

4 4
1 2 1
2 3 2
3 4 4
4 1 8


Output

90


Input

8 6
1 2 2
2 3 1
2 4 4
4 5 5
4 6 3
7 8 5


Output

62

Note

In the first example the are 6 interesting triples: 

  1. (1, 2, 1)
  2. (1, 3, 2)
  3. (1, 4, 3)
  4. (2, 3, 3)
  5. (2, 4, 2)
  6. (3, 4, 1)

The sum is equal to 1 + 2 + 3 + 3 + 2 + 1 = 12.

In the second example the are 12 interesting triples: 

  1. (1, 2, 1)
  2. (2, 3, 2)
  3. (1, 3, 3)
  4. (3, 4, 4)
  5. (2, 4, 6)
  6. (1, 4, 7)
  7. (1, 4, 8)
  8. (2, 4, 9)
  9. (3, 4, 11)
  10. (1, 3, 12)
  11. (2, 3, 13)
  12. (1, 2, 14)

The sum is equal to 1 + 2 + 3 + 4 + 6 + 7 + 8 + 9 + 11 + 12 + 13 + 14 = 90.
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int mxn = 400005, maxnn = 100005;
const int mod = 1e9 + 7;
long long ans;
int n, m, num, cir, r, cnt;
int head[maxnn], que[maxnn];
struct edge {
  int to, next;
  long long w;
} f[mxn << 2];
long long p[70], circle[mxn], dis[maxnn], dig[2], pw[105];
inline void add(int u, int v, long long w) {
  f[++cnt].to = v, f[cnt].w = w, f[cnt].next = head[u], head[u] = cnt;
}
inline void dfs(int u, int fa, long long now) {
  dis[u] = now, que[++num] = u;
  for (int i = head[u]; i; i = f[i].next) {
    int v = f[i].to;
    if (v == fa) continue;
    if (dis[v] == -1)
      dfs(v, u, dis[u] ^ f[i].w);
    else
      circle[++cir] = dis[u] ^ dis[v] ^ f[i].w;
  }
}
inline void init() {
  int i, j;
  r = 0;
  memset(p, 0, sizeof p);
  for (i = 1; i <= cir; i++) {
    long long x = circle[i];
    for (j = 62; j >= 0; j--) {
      if (!(x >> j)) continue;
      if (!p[j]) {
        p[j] = x;
        break;
      }
      x ^= p[j];
    }
  }
  for (j = 0; j <= 62; j++)
    if (p[j]) r++;
}
inline void calc() {
  init();
  int i, j;
  for (j = 0; j <= 62; j++) {
    bool flag = 0;
    dig[0] = dig[1] = 0;
    for (i = 1; i <= num; i++) dig[(dis[que[i]] >> j) & 1]++;
    for (i = 0; i <= 62; i++)
      if ((p[i] >> j) & 1) {
        flag = 1;
        break;
      }
    long long now =
        (dig[0] * (dig[0] - 1) / 2 + dig[1] * (dig[1] - 1) / 2) % mod;
    if (flag) {
      if (r) now = now * pw[r - 1] % mod;
      now = now * pw[j] % mod;
      ans = (ans + now) % mod;
    }
    now = dig[0] * dig[1] % mod;
    if (flag) {
      if (r) now = now * pw[r - 1] % mod;
    } else
      now = now * pw[r] % mod;
    now = now * pw[j] % mod;
    ans = (ans + now) % mod;
  }
}
int main() {
  int i, j, u, v;
  long long w;
  memset(dis, -1, sizeof dis);
  pw[0] = 1;
  for (j = 1; j <= 100; j++) pw[j] = pw[j - 1] * 2 % mod;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%lld", &u, &v, &w);
    add(u, v, w), add(v, u, w);
  }
  for (i = 1; i <= n; i++)
    if (dis[i] == -1) {
      num = cir = 0;
      dfs(i, 0, 0);
      calc();
    }
  printf("%lld", ans);
  return 0;
}
