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]

for j in range(Q):
    ls.append([a for a,x in enumerate(A) if x == B[j]])
    ans -= (B[j]-C[j])*len(ls[j])
    print(ans)
    for i in range(len(ls[j])):
        D[ls[j][i]] = C[j]
    #for i in range(len(lsans)):
    #print (lsans[i])
