MOD = 998244353 def main(): import sys input = sys.stdin.read data = input().split() idx = 0 H = int(data[idx]); idx +=1 W = int(data[idx]); idx +=1 K = int(data[idx]); idx +=1 total = 0 for _ in range(K): x = int(data[idx]); idx +=1 y = int(data[idx]); idx +=1 v = int(data[idx]); idx +=1 s = x + y t = x - y res = 0 # Case 1-1 a = max(x - y + 1, x + y - W, 1) b = min(x, H, s - 1) if a <= b: n = b - a + 1 A = 2 * x - 2 * a + 1 B = 2 * x - 2 * b + 1 res += n * (A + B) // 2 # Case 1-2 a = max(x - y + 1, 1) b = min(x + y - W - 1, x, H, s - 1) if a <= b: first = W + t + 1 - a last = W + t + 1 - b term = (first + last) * (b - a + 1) // 2 res += term # Case 2-1 a = max(x + y - W, 1) b = min(x - y, x + y - 1, H) if a <= b: first = s - a last = s - b term = (first + last) * (b - a + 1) // 2 res += term # Case 2-2 a = 1 b = min(x + y - W - 1, x - y, H) if a <= b: res += W * (b - a + 1) res %= MOD total = (total + res * v) % MOD print(total % MOD) if __name__ == "__main__": main()