H,W,K=map(int,input().split()) def cnt(x,y): retu=(x+1)**2 if x-y>0: retu-=(x-y)*(x-y+1)//2 if x+y-(W-1)>0: retu-=(x+y-(W-1))*(x+y-(W-1)+1)//2 return retu ans=0 mod=998244353 for k in range(K): x,y,v=map(int,input().split()) x-=1;y-=1 ans+=v*cnt(x,y) ans%=mod print(ans)