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())
#print(B,C)
#print(A)
a = 0
for i in range(N):
    a += A[i]
#print(a)
for j in range(Q):
    for i in range(N):
        if A[i] == B[j]:
            a = a + (C[j]-A[i])
            A[i] = C[j]
    #print(A)
    print(a)
