h, w, k = map(int, input().split()) mod = 998244353 ans = 0 inv2 = pow(2, mod - 2, mod) for _ in range(k): x, y, v = map(int, input().split()) cnt = pow(x, 2, mod) if y < x: d = x - y cnt -= d * (d + 1) % mod * inv2 % mod cnt %= mod if (w - y) < x - 1: d = x - (w - y) - 1 cnt -= d * (d + 1) % mod * inv2 % mod cnt %= mod ans += v * cnt % mod ans %= mod print(ans)