n = int(input())
A = list(map(int, input().split()))
q = int(input())

B=[]
C=[]
for i in range(q):
    b1,c1=map(int, input().split())
    B.append(b1)
    C.append(c1)

# print(A)
for i in range(q):
    A=[ C[i] if B[i]==a else a for a in A ]
    print(sum(A))
