#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
long long oula(long long x) {
  long long res = x;
  for (int i = 2; i <= x / i; ++i) {
    if (x % i == 0) {
      res = res / i * (i - 1);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) res = res / x * (x - 1);
  return res;
}
long long quickmod(long long a, long long n, long long m) {
  long long s = 1;
  while (n) {
    if (n & 1) {
      s = s * a % m;
    }
    a = (a * a) % m;
    n = n / 2;
  }
  return s;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void ex_gcd(long long a, long long b, long long &x, long long &y,
            long long &d) {
  if (!b) {
    d = a, x = 1, y = 0;
  } else {
    ex_gcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
long long inv(long long t, long long p) {
  long long d, x, y;
  ex_gcd(t, p, x, y, d);
  return d == 1 ? (x % p + p) % p : -1;
}
bool isPrime(long long x) {
  if (x == 2) return true;
  if (x % 2 == 0) return false;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
inline int in() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 1e5 + 5;
long long dis[N];
int n, m;
vector<pair<int, long long> > G[N];
bool vis[N];
int have[65];
struct l_b {
  long long b[65];
  int num;
  inline void init() {
    num = 0;
    memset(b, 0, sizeof b);
  }
  inline bool insert(long long x) {
    for (int i = 62; i >= 0; --i) {
      if (x >> i & 1) {
        if (b[i])
          x ^= b[i];
        else {
          num++;
          b[i] = x;
          return true;
        }
      }
    }
    return false;
  }
  inline long long solve(int sz) {
    long long res = 0;
    long long n_2 = (long long)sz * (sz - 1) / 2;
    for (int j = 62; j >= 0; --j) {
      bool good = false;
      for (int i = 0; i <= 62; ++i)
        if (b[i] >> j & 1) good = true;
      if (good) {
        long long now = quickmod(2, num - 1 + j, mod) * n_2 % mod;
        res = (res + now) % mod;
      } else {
        long long now =
            quickmod(2, num + j, mod) * have[j] * (sz - have[j]) % mod;
        res = (res + now) % mod;
      }
    }
    return res;
  }
} base;
int sz;
void dfs(int u, long long v) {
  vis[u] = true;
  dis[u] = v;
  sz++;
  for (int i = 0; i <= 62; ++i)
    if (dis[u] >> i & 1) have[i]++;
  for (auto I : G[u]) {
    if (vis[I.first]) {
      base.insert(dis[I.first] ^ v ^ I.second);
      continue;
    } else
      dfs(I.first, v ^ I.second);
  }
}
int main() {
  while (cin >> n >> m) {
    for (int i = 1; i <= m; ++i) {
      int x = in();
      int y = in();
      long long w;
      scanf("%lld", &w);
      G[x].emplace_back(pair<int, long long>{y, w});
      G[y].emplace_back(pair<int, long long>{x, w});
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i]) {
        base.init();
        memset(have, 0, sizeof have);
        sz = 0;
        dfs(i, 0);
        ans = (ans + base.solve(sz)) % mod;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
