#include <bits/stdc++.h>
using namespace std;
const int N = 200006;
vector<pair<long long, long long> > a[N];
int vis[N], vis2[N][65];
long long val[N];
vector<long long> cy;
bool gg[100];
void dfs(int i, int p) {
  for (int j = 0; j < a[i].size(); j++) {
    if (vis[a[i][j].first] == 0) {
      vis[a[i][j].first] = vis[i] + 1;
      val[a[i][j].first] = val[i] ^ a[i][j].second;
      dfs(a[i][j].first, i);
    } else {
      if (vis[a[i][j].first] > vis[i] && a[i][j].first != p) {
        cy.push_back(val[a[i][j].first] ^ val[i] ^ a[i][j].second);
      }
    }
  }
}
pair<int, int> dfs1(int i, int bitt) {
  vis2[i][bitt] = 1;
  pair<int, int> zz = make_pair(0, 0);
  if ((val[i] & (1LL << bitt)))
    zz.second++;
  else
    zz.first++;
  for (int j = 0; j < a[i].size(); j++) {
    if (vis2[a[i][j].first][bitt] == 0) {
      pair<int, int> bb = dfs1(a[i][j].first, bitt);
      zz = make_pair(zz.first + bb.first, zz.second + bb.second);
    }
  }
  return zz;
}
vector<long long> gaussian_elim(vector<long long> a, int n, int m) {
  for (int col = 0, row = 0; col < m && row < n; ++col) {
    for (int i = row; i < n; ++i)
      if (((1LL << col) & a[i])) {
        swap(a[i], a[row]);
        break;
      }
    if (!((1LL << col) & a[row])) continue;
    for (int i = 0; i < n; ++i)
      if (i != row && ((1LL << col) & a[i])) a[i] ^= a[row];
    ++row;
  }
  vector<long long> nxt;
  for (int i = 0; i < a.size(); i++)
    if (a[i] != 0) nxt.push_back(a[i]);
  return nxt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long t;
    cin >> u >> v >> t;
    a[u].push_back(make_pair(v, t));
    a[v].push_back(make_pair(u, t));
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      cy.clear();
      vis[i] = 1;
      dfs(i, -1);
      cy = gaussian_elim(cy, cy.size(), 62);
      for (long long j = 0; j < 63; j++) {
        gg[j] = false;
      }
      for (int k = 0; k < cy.size(); k++) {
        for (long long j = 0; j < 63; j++) {
          if ((cy[k] & (1LL << j))) gg[j] = true;
        }
      }
      long long ff = (1LL << cy.size());
      int basis = cy.size();
      int cnt1 = 0, cnt2 = 0;
      for (int j = 0; j < 63; j++) {
        pair<int, int> zz = dfs1(i, j);
        cnt1 = zz.first;
        cnt2 = zz.second;
        long long w1 = (1LL * cnt1 * cnt2) % 1000000007;
        long long w2 = (1LL << j) % 1000000007;
        w1 = (w1 * w2) % 1000000007;
        if (gg[j]) {
          cnt1 = cnt1 + cnt2;
          long long zz = (1LL * cnt1 * (cnt1 - 1LL)) / 2LL;
          zz %= 1000000007;
          zz = (zz * w2) % 1000000007;
          zz = (zz * ((ff / 2LL) % 1000000007)) % 1000000007;
          ans = (ans + zz) % 1000000007;
        } else {
          ans = (ans + (w1 * ((ff) % 1000000007) % 1000000007)) % 1000000007;
        }
      }
    }
  }
  cout << ans << endl;
}
