n,m = map(int,input().split())
a = [0]+list(map(int,input().split()))
p = sum(v**2 for v in a)
for _ in range(int(input())):
    c,k,d = map(int,input().split())
    p -= a[c]**2+a[d]**2
    a[c] -= k; a[d] += k
    p += a[c]**2+a[d]**2
    print(p)