#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
vector<pair<int, ll> > E[200001];
ll W[200001];
int kazu[60];
void dfs(int u, int mae) {
	for (auto v : E[u]) {
		if (v.first != mae) {
			W[v.first] = W[u] ^ v.second;
			dfs(v.first, u);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	rep(i, N - 1) {
		int u, v;
		ll w;
		cin >> u >> v >> w;
		E[u].pb({ v,w });
		E[v].pb({ u,w });
	}
	dfs(1, 0);

	ll kotae = 0;
	rep1(i, N) {
		kotae += W[i] % mod * (N - 1) % mod;
	}
	kotae %= mod;

	rep1(i, N) {
		rep(j, 60) if (W[i] >> j & 1) {
			kazu[j]++;
		}
	}
	rep(j, 60) {
		kotae -= ((1ll << j) % mod) * kazu[j] % mod * (kazu[j] - 1) % mod;
	}

	co((kotae% mod + mod) % mod);

	Would you please return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll Gcd(ll a, ll b) { return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b) { return a / Gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main(){
	int n, x;
	cin >> n >> x;
	string s;
	cin >> s;
	rep(i, n) {
		if (s[i] == 'o') x++;
		else if (s[i] == 'x' && x > 0) x--;
	}
	cout << x << endl;
	return 0;
}