#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second
template<int MOD=1000000007>
struct modint{
	/*static modint inv[2005];
	static void init(){
		for(int i=0;i<2005;i++)inv[i]=modpow(modint(i),MOD-2);
	}*/
	ull val;
	modint(ull x){ val=x%MOD; }
	modint(){}
	friend modint modpow(modint x,ull k){
		modint ret(1ULL);
		while(k>0){
			if(k&1ULL)ret*=x;
			x*=x;
			k>>=1;
		}
		return ret;
	}
	modint& operator +=(const modint& rhs){
		this->val+=rhs.val;
		if(this->val>=MOD)this->val-=MOD;
		return *this;
	}
	friend modint operator+(modint lhs, const modint& rhs){
		lhs+=rhs;
		return lhs;
	}
	modint& operator -=(const modint& rhs){
		this->val+=MOD-rhs.val;
		if(this->val>=MOD)this->val-=MOD;
		return *this;
	}
	friend modint operator-(modint lhs, const modint& rhs){
		lhs-=rhs;
		return lhs;
	}
	modint& operator *=(const modint& rhs){
		this->val*=rhs.val;
		this->val%=MOD;
		return *this;
	}
	friend modint operator*(modint lhs, const modint& rhs){
		lhs*=rhs;
		return lhs;
	}
	modint& operator /=(const modint& rhs){
		(*this)*=modpow(rhs,MOD-2);
		//(*this)*=inv[rhs.val];
		return *this;
	}
	friend modint operator/(modint lhs, const modint& rhs){
		lhs/=rhs;
		return lhs;
	}
};
//template<int MOD>
//modint<MOD> modint<MOD>::inv[2005];

const int MOD=998244353;
typedef modint<MOD> mi;

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	if(n>m)swap(n,m);
	if(n==1){
		cout<<modpow(mi(k),m).val<<endl;
		return 0;
	}
	
	mi ret=0;
	for(int i=1;i<=k;i++){
		mi l=modpow(mi(i),n)-modpow(mi(i-1),n);
		mi r=modpow(mi(k-i+1),m);
		ret+=l*r;
	}
	cout<<ret.val<<endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
vector<pair<int,ll>> E[201010];
const ll mo=1000000007;
ll pat;
ll C[2];

void dfs(int cur,int pre,int id,int d) {
	C[id]++;
	FORR2(e,c,E[cur]) if(e!=pre) {
		if(c&(1LL<<d)) {
			dfs(e,cur,id^1,d);
		}
		else {
			dfs(e,cur,id,d);
		}
		
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		ll a;
		cin>>x>>y>>a;
		E[x-1].push_back({y-1,a});
		E[y-1].push_back({x-1,a});
	}
	
	ll ret=0;
	FOR(i,60) {
		ZERO(C);
		dfs(0,0,0,i);
		
		(ret+=C[0]*C[1]%mo*((1LL<<i)%mo))%=mo;
		
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
