#include int main () { int h = 0; long long w = 0LL; int k = 0; long long x = 0LL; long long y = 0LL; long long v = 0LL; int res = 0; long long ans = 0LL; long long mod_num = 998244353LL; res = scanf("%d", &h); res = scanf("%lld", &w); res = scanf("%d", &k); for (int i = 0; i < k; i++) { long long cnt = 0LL; res = scanf("%lld", &x); res = scanf("%lld", &y); res = scanf("%lld", &v); cnt = (x*x)%mod_num; if (x-y > 0LL) { cnt -= (((x-y)*(x-y+1LL))/2LL)%mod_num; cnt += mod_num; cnt %= mod_num; } if (x-(w-y+1LL) > 0LL) { cnt -= (((x-(w-y+1LL))*(x-(w-y+1LL)+1LL))/2LL)%mod_num; cnt += mod_num; cnt %= mod_num; } ans += cnt*v; ans %= mod_num; } printf("%lld\n", ans%mod_num); return 0; }