N, M = map(int, input().split()) A = list(map(int, input().split())) count = [0]*M calc = 0 for i in range(M): count[i] = A[i] calc += count[i]**2 Q = int(input()) for i in range(Q): c, k, d = map(int, input().split()) calc -= count[c-1]**2 count[c-1] -= k calc += count[c-1]**2 calc -= count[d-1]**2 count[d-1] += k calc += count[d-1]**2 print(calc) #print(count)