""" """ import sys from sys import stdin N,M = map(int,stdin.readline().split()) A = list(map(int,stdin.readline().split())) ans = sum( [i**2 for i in A] ) Q = int(stdin.readline()) ANS = [] for i in range(Q): C,K,D = map(int,stdin.readline().split()) C -= 1 D -= 1 ans -= A[C] ** 2 ans -= A[D] ** 2 A[C] -= K A[D] += K ans += A[C] ** 2 ans += A[D] ** 2 ANS.append(ans) print (*ANS,sep="\n")