N,M = map(int,input().split()) A = list(map(int,input().split())) S = 0 for i in range(M): S += A[i]*A[i] Q = int(input()) for _ in range(Q): C,K,D = map(int,input().split()) S -= A[C-1]*A[C-1] S -= A[D-1]*A[D-1] A[C-1] -= K A[D-1] += K S += A[C-1]*A[C-1] S += A[D-1]*A[D-1] print(S)