#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U>& a) {
  out << "[" << a.first << " " << a.second << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[ ";
  for (auto& it : a) out << it << " ";
  out << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const set<T>& a) {
  out << "[ ";
  for (auto& it : a) out << it << " ";
  out << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const multiset<T>& a) {
  out << "[ ";
  for (auto& it : a) out << it << " ";
  out << "]";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U>& a) {
  for (auto& it : a) out << it.first << " -> " << it.second << " | ";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, const multimap<T, U>& a) {
  for (auto& it : a) out << it.first << " -> " << it.second << " | ";
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long MOD = 1e9 + 7;
template <class vecType>
struct xorSpace {
  long long dimension, rank;
  vector<long long> basis;
  vector<vecType> basisVectors;
  xorSpace(long long dim) {
    dimension = dim;
    rank = 0;
    basis.resize(dim);
    basisVectors.resize(0);
  }
  inline long long getValAtDim(vecType v, long long dim) {
    return (((1LL << dim) & v) != 0);
  }
  bool addToBasis(vecType num) {
    long long pos = -1;
    for (long long i = dimension - 1; i >= 0; i--) {
      if (getValAtDim(num, i) != 0) {
        if (basis[i] == 0) {
          pos = i;
          break;
        } else {
          num ^= basis[i];
        }
      }
    }
    if (pos != -1) {
      basis[pos] = num;
      basisVectors.push_back(num);
      rank++;
      return true;
    }
    return false;
  }
};
const long long N = 200010, BITS = 61;
vector<pair<long long, long long> > G[N];
long long n, m, xoroot[N], seen[N];
void dfs(long long node, long long xorPath, xorSpace<long long>& X,
         vector<long long>& xoroots) {
  seen[node] = true;
  xoroot[node] = xorPath;
  xoroots.push_back(xorPath);
  for (auto el : G[node]) {
    long long next = el.first, w = el.second;
    if (not seen[next]) {
      dfs(next, xorPath ^ w, X, xoroots);
    } else {
      X.addToBasis(xoroot[node] ^ xoroot[next] ^ w);
    }
  }
}
void Main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    --u;
    --v;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (not seen[i]) {
      xorSpace<long long> X(BITS);
      vector<long long> xoroots;
      dfs(i, 0, X, xoroots);
      long long basisOr = 0, span = (1LL << (X.rank));
      for (long long vec : X.basisVectors) {
        basisOr |= vec;
      }
      long long temp = 1;
      for (long long bit = 0; bit < BITS; bit++) {
        long long times = 0;
        long long zeros = 0;
        long long ones = 0;
        for (long long xrt : xoroots) {
          if (temp & xrt) {
            ones++;
          } else {
            zeros++;
          }
        }
        if (basisOr & temp) {
          times += (zeros * ones * ((span / 2) % MOD)) % MOD;
          times += ((((zeros * (zeros - 1)) / 2) + ((ones * (ones - 1)) / 2)) *
                    ((span / 2) % MOD)) %
                   MOD;
        } else {
          times += (zeros * ones * (span % MOD)) % MOD;
        }
        ans += ((times % MOD) * (temp % MOD)) % MOD;
        temp <<= 1;
      }
    }
  }
  cout << ans % MOD << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Main();
}
