N,M=map(int,input().split()) A=list(map(int,input().split())) power_now=0 for i in range(M): power_now+=A[i]**2 Q=int(input()) for _ in range(Q): c,k,d=map(int,input().split()) c-=1 d-=1 a_c=A[c] a_d=A[d] power_now-=(a_c**2+a_d**2) A[d]+=k A[c]-=k a_c=A[c] a_d=A[d] power_now+=(a_c**2+a_d**2) print(power_now)