#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n, e;
vector<pair<int, long long> > adj[100005];
bool done[100005], atleast_1_one[62];
set<long long> vector_space;
vector<long long> basis;
long long cnt[2][65], Xor[100005];
void dfs(int v, int par, long long xorval) {
  Xor[v] = xorval;
  done[v] = true;
  for (int i = 0; i < 62; i++)
    if ((xorval >> i) & 1)
      cnt[1][i]++;
    else
      cnt[0][i]++;
  for (auto it : adj[v])
    if (it.first != par) {
      if (done[it.first]) {
        vector_space.insert((xorval ^ it.second) ^ Xor[it.first]);
      } else {
        dfs(it.first, v, xorval ^ it.second);
      }
    }
}
void get_basis() {
  for (auto x : vector_space) {
    for (auto y : basis) x = min(x, x ^ y);
    if (x > 0) basis.push_back(x);
  }
}
int main() {
  scanf("%d%d", &n, &e);
  for (int i = 0; i < e; i++) {
    int a, b;
    long long c;
    scanf("%d%d%lld", &a, &b, &c);
    adj[a].push_back(pair<int, long long>(b, c));
    adj[b].push_back(pair<int, long long>(a, c));
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (done[i]) continue;
    vector_space.clear();
    basis.clear();
    memset(cnt, 0, sizeof(cnt));
    memset(atleast_1_one, 0, sizeof(atleast_1_one));
    dfs(i, -1, 0);
    get_basis();
    for (auto x : basis)
      for (int i = 0; i < 62; i++)
        if ((x >> i) & 1) atleast_1_one[i] = true;
    int rank = (int)basis.size();
    for (int i = 0; i < 62; i++) {
      long long val0 =
          (cnt[0][i] * (cnt[0][i] - 1) / 2 + cnt[1][i] * (cnt[1][i] - 1) / 2) %
          (1000000007LL);
      long long val1 = (cnt[0][i] * cnt[1][i]) % (1000000007LL);
      if (atleast_1_one[i]) {
        ans +=
            ((pwr(2, rank - 1) * (val0 + val1)) % (1000000007LL)) * pwr(2, i);
        ans %= (1000000007LL);
      } else {
        ans += ((pwr(2, rank) * val1) % (1000000007LL)) * pwr(2, i);
        ans %= (1000000007LL);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
