N = int(input())
A = list(map(int, input().strip().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q

for i in range(Q):
    B[i],C[i] = map(int,input().split())

def func(A,b,c):
    for i in range(len(A)):
        if A[i]==b:
            A[i]=c

for i in range(Q):
    func(A,B[i],C[i])
    print(sum(A))