N, M = map(int, input().split()) A = list(map(int, input().split())) res = 0 for a in A: res += a * a Q = int(input()) for q in range(Q): c, k, d = map(int, input().split()) res -= A[c - 1] * A[c - 1] + A[d - 1] * A[d - 1] A[c - 1] -= k A[d - 1] += k res += A[c - 1] * A[c - 1] + A[d - 1] * A[d - 1] print(res)