import sys input = sys.stdin.readline n, m = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(m): ans += pow(A[i], 2) q = int(input()) for _ in range(q): c, k, d = map(int, input().split()) c -= 1 d -= 1 ans -= pow(A[c], 2) + pow(A[d], 2) A[c] -= k A[d] += k ans += pow(A[c], 2) + pow(A[d], 2) print(ans)