#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
vector<pair<int, long long>> a[N];
bool visit[N];
int cnt[60][2];
long long path[N];
vector<bitset<60>> cycle_base;
void add_cycle(bitset<60> cur) {
  for (int i = 0; i < cycle_base.size(); ++i) {
    for (int j = i; j < 60; ++j) {
      if (cur[j]) {
        if (cycle_base[i][j]) {
          cur ^= cycle_base[i];
        } else {
          cycle_base[i] ^= cur;
          cur ^= cycle_base[i];
        }
        break;
      } else if (cycle_base[i][j]) {
        break;
      }
    }
  }
  if (cur != 0) cycle_base.push_back(cur);
}
void DFS(int u, int parent, long long cur) {
  path[u] = cur;
  visit[u] = true;
  for (int k = 0; k < 60; ++k) {
    if (cur & (1LL << k)) {
      cnt[k][1]++;
    } else {
      cnt[k][0]++;
    }
  }
  for (auto& it : a[u]) {
    int v = it.first;
    if (v == parent) continue;
    if (!visit[v]) {
      DFS(v, u, cur ^ it.second);
    } else {
      add_cycle(path[u] ^ path[v] ^ it.second);
    }
  }
}
long long comb2(long long n) { return n * (n - 1) / 2 % MOD; }
int solve(int u) {
  long long ret = 0;
  memset(cnt, 0, sizeof(cnt));
  cycle_base.clear();
  DFS(u, -1, 0LL);
  int rank = cycle_base.size();
  long long X = (1LL << (rank - 1)) % MOD;
  long long Y = (1LL << rank) % MOD;
  for (int k = 0; k < 60; ++k) {
    bool found = false;
    for (auto& it : cycle_base) {
      if (it[k]) {
        found = true;
        break;
      }
    }
    if (found) {
      ret += comb2(cnt[k][0] + cnt[k][1]) * X % MOD * ((1LL << k) % MOD) % MOD;
    } else {
      ret += (long long)cnt[k][0] * cnt[k][1] % MOD * Y % MOD *
             ((1LL << k) % MOD) % MOD;
    }
  }
  return ret % MOD;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    long long z;
    scanf("%d%d%I64d", &x, &y, &z);
    --x;
    --y;
    a[x].emplace_back(y, z);
    a[y].emplace_back(x, z);
  }
  long long ret = 0;
  for (int i = 0; i < n; ++i) {
    if (!visit[i]) ret += solve(i);
  }
  printf("%d\n", ret % MOD);
  return 0;
}
