n, m = map(int, input().split()) h = list(map(int, input().split())) now = sum(x * x for x in h) for _ in range(int(input())): c, k, d = map(int, input().split()) c -= 1 d -= 1 now -= h[c] * h[c] + h[d] * h[d] h[c] -= k h[d] += k now += h[c] * h[c] + h[d] * h[d] print(now)