#include using namespace std; const int mod = 998244353; // const int mod = 1000000007; struct modint { long long a = 0; modint(long long x = 0) {while (x < 0) x += mod; a = x % mod;} modint(const modint &r) {a = r.a;} modint operator -(){return modint(-a);} modint operator +(const modint &r) {return modint(*this) += r;} modint operator -(const modint &r) {return modint(*this) -= r;} modint operator *(const modint &r) {return modint(*this) *= r;} modint &operator +=(const modint &r) { a += r.a; if(a >= mod) a -= mod; return *this; } modint &operator -=(const modint &r) { a -= r.a; if(a < 0) a += mod; return *this; } modint &operator *=(const modint &r) { a = a * r.a % mod; return *this; } modint pow(long long r) const { if (!r) return 1; modint x = pow(r >> 1); x *= x; if (r & 1) x *= *this; return x; } modint inverse() const { return pow(mod - 2); } modint& operator/=(const modint r) { return (*this) *= r.inverse(); } modint operator/(const modint r) const { modint res(*this); return res /= r; } }; istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = t; return is; } ostream &operator<<(ostream &os, const modint& x) { return os << x.a; } const int MAX = 500044; modint fac[MAX], inv[MAX], finv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * modint(i); inv[i] = - inv[mod % i] * modint(mod / i); finv[i] = finv[i - 1] * inv[i]; } } modint Com(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } modint Per(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k]; } using Mint = modint; int main() { int h, w, k; cin >> h >> w >> k; vector x(k), y(k), v(k); for (int i = 0; i < k; i++) { cin >> x[i] >> y[i] >> v[i]; } Mint ans = 0; for (int i = 0; i < k; i++) { long long A = max(1, x[i] - y[i] + 1); Mint B = (A + x[i]) * (x[i] - A + 1) / 2; long long C = max(1, x[i] - (w - y[i])); Mint D = (C + x[i]) * (x[i] - C + 1) / 2; ans += Mint(v[i]) * Mint(B + D - x[i]); } cout << ans << endl; }