N=int(input())
A = list(map(int,input().split()))
Q=int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i]=map(int,input().split())
ls = []
lsans=[]
D = A
ans = 0
for z in range(N):
    ans += A[z]
    #print(ans)
for j in range(Q):
    ls.append([a for a,x in enumerate(A) if x == B[j]])
    if j >= 1:
        if B[j]==C[j-1]:
            #print("yes")
            ans -= (B[j]-C[j])*(len(ls[j])+n)
    else:
        n = len(ls[j])
        ans -= (B[j]-C[j])*len(ls[j])

    print(ans)
