/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<long long,long long,long long> TUP;
using P = pair<int,int>;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}



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

    int N;cin >> N;
    long long C;cin >> C;
    vector<PLL> s(N);
    vector<long long> cost(N);
    vector<TUP> event;
    long long last = 0;
    for(int i = 0;i<N;i++){
        long long a,b,c;cin >> a >> b >> c;
        s.at(i) = make_pair(a,b);
        last = max(last,b);
        cost.at(i) = c;
        event.push_back(make_tuple(a-1,1,i));
        event.push_back(make_tuple(b,2,i));
    }
    sort(event.begin(),event.end());

    long long now = get<0>(event.at(0));
    long long ans = 0;
    long long nowsum = 0;
    long long ex = 0;
    vector<long long> Time(N);
    for(int i = 0;i<event.size();i++){
        long long T = get<0>(event.at(i));
        int type = get<1>(event.at(i));
        int idx = get<2>(event.at(i));
        if(T == last && type == 2){
            //ex += cost.at(idx);
        }
        if(type == 1){
            if(nowsum > C){
                ans += C * (T - now);
                //nowsum -= cost.at(idx);
            }
            else{
                ans += nowsum * (T - now);
                //nowsum -= cost.at(idx);
            }
            Time.at(idx) = T;
            now = T;
            nowsum += cost.at(idx);
        }
        else if(type == 2){
            if(nowsum > C){
                ans += C * (T - now);
                nowsum -= cost.at(idx);
            }
            else{
                ans += nowsum * (T - now);
                nowsum -= cost.at(idx);
            }
            now = T;
        }
        if(T == last && type == 2){
            //ex += cost.at(idx);
            //cout << nowsum + ex << endl;
            //ans += min(nowsum + ex , C);
            //cout << T << endl;
            //if(nowsum+ex >= C) cout << "u" << endl;
        }
    }
    //for(int i = 0;i<N;i++) ex += cost.at(i);
    cout << ans + min(ex , C) << endl;
    //cout << 163089627821228 - 163089627569438 << endl;

}
// #undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
 
#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif
 
#define ARG4(_1,_2,_3,_4,...) _4
 
#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)
 
#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)
 
#define forv(i,v) for (auto i = v.begin(); i != v.end(); ++i)
#define forr(i,v) for (auto i = v.end(); i != v.begin() && (--i, 1); )
#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;
 
const ld pi = 3.1415926535897932384626433832795l;
 
template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T> inline T abs (T x) {return x > T() ? x : -x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}
 
const ll mod = 998244353;

ll get_st(ll a, int st) {
	ll res = 1;
	while(st) {
		if (st & 1) {
			(res *= a) %= mod;
		}
		(a *= a) %= mod;
		st >>= 1;
	}
	return res;
}

int main () {
	//std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	int n, m, k;
	cin >> n >> m >> k;
	if (n == 1 || m == 1) {
		cout << get_st(k, n * m) << endl;
		return 0;
	}
	ll ans = 0;
	forn(i, 1, k + 1) {
		(ans += (get_st(i, n) - get_st(i - 1, n) + mod) * (get_st(k - i + 1, m) % mod)) %= mod;
	}
	cout << ans << endl;	

	return 0;
}