n, m = map(int, input().split()) A = list(map(int, input().split())) ans = sum(a**2 for a in A) Q = int(input()) for _ in range(Q): c, k, d = map(int, input().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 print(ans)