#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 7;
const int M = 62;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * (inf - 1);
const double pi = acos(-1);
const double eps = 1e-6;
const bool multipleTest = false;
int n, m;
vector<pair<int, long long>> adj[N];
long long gauss[M];
void add(long long x) {
  for (long long i = 0; i <= 60; ++i) {
    if (x & (1ll << i)) {
      if (gauss[i] == 0) {
        gauss[i] = x;
        break;
      } else {
        x ^= gauss[i];
      }
    }
  }
}
int cnt[2][M];
bool check[N];
long long d[N];
int sl = 0;
void dfs(int u, int r) {
  ++sl;
  for (int j = 0; j <= 60; ++j) {
    if (d[u] & (1ll << j))
      cnt[1][j]++;
    else
      cnt[0][j]++;
  }
  for (int j = 0; j < adj[u].size(); ++j) {
    int v = adj[u][j].first;
    long long c = adj[u][j].second;
    if (!check[v]) {
      check[v] = 1;
      d[v] = d[u] ^ c;
      dfs(v, u);
    } else {
      long long now = d[u] ^ d[v] ^ c;
      add(now);
    }
  }
}
long long res = 0;
long long lt[M];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    long long c;
    scanf("%d%d%lld", &u, &v, &c);
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
  }
  lt[0] = 1;
  for (int j = 1; j <= 60; ++j) lt[j] = lt[j - 1] * 2 % inf;
  for (int i = 1; i <= n; ++i)
    if (!check[i]) {
      check[i] = 1;
      d[i] = 0;
      memset(cnt, 0, sizeof(cnt));
      memset(gauss, 0, sizeof(gauss));
      sl = 0;
      dfs(i, -1);
      int r = 0;
      for (int j = 0; j <= 60; ++j)
        if (gauss[j]) ++r;
      for (int j = 0; j <= 60; ++j) {
        int has = 0;
        long long now = 1ll << j;
        for (int d = 0; d <= 60; ++d)
          if (gauss[d] & now) has++;
        long long cur = 0;
        if (!has) {
          cur = now % inf * cnt[0][j] % inf * cnt[1][j] % inf * lt[r] % inf;
        } else {
          long long xx = ((1ll * sl * (sl - 1)) / 2) % inf;
          cur = now % inf * xx % inf * lt[r - 1] % inf;
        }
        res = (res + cur) % inf;
      }
    }
  cout << res << "\n";
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
