n, m = map(int, input().split()) A = list(map(int, input().split())) q = int(input()) ans = sum(a**2 for a in A) for i in range(q): c, k, d = map(int, input().split()) ans -= A[c-1] ** 2 + A[d-1] ** 2 A[c-1] -= k A[d-1] += k ans += A[c-1] ** 2 + A[d-1] ** 2 print(ans)