#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;

long long gcd(long long a, long long b){ return b? gcd(b, a%b) : a; }
long long lcm(long long a, long long b){ return (!a or !b)? 0 : a * b / gcd(a,b); } 
long long  poww(long long  a, long long b){
	long long res = 1;
	while(b){ 
		if(b%2) res = res * a ; 
		a = a * a;  b>>=1;
	} return res;
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;}
template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using li = long long;
using vi = vc<int>;
using ii = pair<int,int>;
// ---- しゃけ ツナマヨ ('-')7
const int mod = 1e9+7;

int Sum(li a, li b){
    return (a+b)%mod;
}

int Mul(li a, li b){
	a%=mod, b%=mod;
    return (a*b)%mod;
}


int main(){_
	auto solve=[&](){
		int n; cin>>n;
		using pl = pair<int,li>;
		vv(pl,v,n);
		fore(i,0,n-1){
			li a,b,c; cin>>a>>b>>c; a--,b--;
			v[a].pb({b,c});
			v[b].pb({a,c});
		}
		vc<li>to(n,0);
		auto f=[&](auto &&f, int u, int pr, li w)->void{
			to[u]=w;
			for(auto [a,b]:v[u])if(pr!=a)f(f,a,u,w^b);
		};
		f(f,0,0,0);
		li res = 0;
		fore(i,0,60){
			li c = 0;
			fore(j,0,n)if(to[j]&(1ll<<i))c++;
			res = Sum(res,Mul(c*(n-c),(1ll<<i)));
		}
		cout<<res<<ENDL;
		

	
	};
	//int t; cin>>t; while(t--)
	solve();

}

#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 998244353;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

ll modpow(ll a, ll p, ll m){
	ll ret = 1;
	while(p){
		if(p&1) ret = ret * a % m;
		a = a * a % m;
		p >>= 1;
	}
	return ret;
}

int main(){
	ll n, m, k;
	scanf("%ld %ld %ld", &n, &m, &k);

	ll ans = 0;
	REP(i, 1, k+1){
		ll x = modpow(k-i+1, m, MOD) - modpow(k-i, m, MOD);
		x = (x + MOD) % MOD;
		if(n==1) ans += x;
		else{
			ll y = modpow(i, n, MOD);
			if(m==1) y = (y - modpow(i-1, n, MOD) + MOD) % MOD;
			ans += x * y % MOD;
		}
		ans %= MOD;
	}
	printf("%ld\n", ans);
	return 0;
}

