def solve(): N,M=map(int,input().split()) A=[0]+list(map(int,input().split())) power=sum(a*a for a in A) Q=int(input()) Ans=[0]*Q for q in range(Q): C,K,D=map(int,input().split()) power+=(A[D]+K)*(A[D]+K)+(A[C]-K)*(A[C]-K)-(A[D]*A[D]+A[C]*A[C]) A[D]+=K; A[C]-=K Ans[q]=power return Ans #================================================== import sys input=sys.stdin.readline write=sys.stdout.write write("\n".join(map(str,solve())))