import sys input = sys.stdin.readline N,M=map(int,input().split()) seg_el=1<<((M+100).bit_length()) SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 def seg_function(x,y): return x+y def update(n,x,seg_el): # A[n]をxへ更新 i=n+seg_el SEG[i]=x i>>=1 # 子ノードへ while i!=0: SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) i>>=1 def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる L=l+seg_el R=r+seg_el ANS1=0 ANS2=0 while L>=1 R>>=1 return seg_function(ANS1, ANS2) def getvalue(n,seg_el): # 一点の値を取得 i=n+seg_el ANS=0 ANS=SEG[i] i>>=1# 子ノードへ while i!=0: ANS+=SEG[i] i>>=1 return ANS def updates(l,r,x): # 区間[l,r)を+x更新. L=l+seg_el R=r+seg_el while L>=1 R>>=1 SEG2=[0]*(2*seg_el) def getvalue2(n,seg_el): # 一点の値を取得 i=n+seg_el ANS=0 ANS=SEG2[i] i>>=1# 子ノードへ while i!=0: ANS+=SEG2[i] i>>=1 return ANS def updates2(l,r,x): # 区間[l,r)を+x更新. L=l+seg_el R=r+seg_el while L>=1 R>>=1 ANS=0 X=[[] for i in range(N+1)] for i in range(N): a,l,r=map(int,input().split()) update(i+1,a,seg_el) updates2(l,r+1,1) ANS+=a*(r-l+1) X[i+1]=(a,i+1,l,r) for i in range(N+1): if X[i]==[]: continue a,p,l,r=X[i] k=getvalue2(p,seg_el) ANS-=k*a #print(ANS) Q=int(input()) for tests in range(Q): x,y,u,v=map(int,input().split()) a,p,l,r=X[x] ANS+=getvalue2(p,seg_el)*a #print(ANS) ANS-=a*(r-l+1) #print(ANS) update(p,0,seg_el) updates2(l,r+1,-1) ANS+=getvalues(l,r+1) #print(ANS) #updates2(l,r+1,-1) X[x]=(a,y,u,v) ANS+=a*(v-u+1) #print(ANS) ANS-=getvalue2(y,seg_el)*a updates2(u,v+1,1) update(y,a,seg_el) ANS-=getvalues(u,v+1) update(y,a,seg_el) print(ANS)