#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const long double PI = acos(-1);
const int N = 1e5 + 5;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct edge {
  int u, v;
  long long wt;
  bool operator<(edge e) const { return u == e.u ? v < e.v : u < e.u; }
};
int n, m;
int vis[N];
long long x[N];
vector<edge> adj[N];
vector<edge> ed;
set<edge> used, notused;
void dfs(int u, long long p) {
  vis[u] = 1;
  x[u] = p;
  for (auto e : adj[u]) {
    ed.push_back(e);
    if (!vis[e.v]) {
      dfs(e.v, p ^ e.wt);
      used.insert(e);
    }
  }
}
vector<bitset<62>> num, base;
int gauss() {
  int sz = (int)num.size();
  int bs = 0;
  for (int i = 0; i < 62; i++) {
    bool found = false;
    for (int j = bs; j < sz; j++)
      if (num[j][i]) {
        found = true;
        swap(num[j], num[bs]);
      }
    for (int j = bs + 1; j < sz; j++)
      if (num[j][i]) {
        num[j] ^= num[bs];
      }
    if (found) base.push_back(num[bs]), bs++;
  }
  return base.size();
}
bool has[N];
bool contains(set<edge> &s, edge e) {
  edge rev = {e.v, e.u, e.wt};
  return s.count(rev) or s.count(e);
}
long long solve(vector<edge> &ed) {
  memset(has, 0, sizeof has);
  vector<int> vtx;
  for (auto e : ed) {
    vtx.push_back(e.u);
    vtx.push_back(e.v);
  }
  sort(vtx.begin(), vtx.end());
  long long n = unique(vtx.begin(), vtx.end()) - vtx.begin();
  vtx.resize(n);
  for (auto e : ed)
    if (!contains(used, e)) {
      long long wt = x[e.u] ^ x[e.v] ^ e.wt;
      if (!contains(notused, e)) {
        num.push_back(wt);
        notused.insert(e);
      }
    }
  int b = gauss();
  for (int i = 0; i < 62; i++)
    for (auto j : base)
      if (j[i]) has[i] = true;
  long long sum = 0;
  for (int i = 0; i < 62; i++) {
    long long one = 0, zero = 0;
    for (int j : vtx) {
      if (x[j] & (1ll << i))
        one++;
      else
        zero++;
    }
    if (has[i] and b != 0) {
      long long term1 = (1ll << i) % MOD;
      long long term2 = (1ll << (b - 1)) % MOD;
      long long term3 = ((n * (n - 1)) / 2) % MOD;
      term1 = (term1 * term2) % MOD;
      term1 = (term1 * term3) % MOD;
      sum = (sum + term1) % MOD;
    } else {
      long long term1 = (1ll << i) % MOD;
      long long term2 = (1ll << b) % MOD;
      term1 = (term1 * term2) % MOD;
      term1 = (term1 * one) % MOD;
      term1 = (term1 * zero) % MOD;
      sum = (sum + term1) % MOD;
    }
  }
  return sum;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    long long t;
    scanf("%d %d %lld", &u, &v, &t);
    edge eu = {u, v, t};
    edge ev = {v, u, t};
    adj[u].push_back(eu);
    adj[v].push_back(ev);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      ed.clear();
      num.clear();
      base.clear();
      used.clear();
      dfs(i, 0);
      ans = (ans + solve(ed)) % MOD;
    }
  printf("%lld\n", ans);
  return 0;
}
