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

Q=int(input())
for i in range(Q):
    b, c = map(int, input().split())
    wa=0
    for j in range(len(A)):
        if A[j]==b:
            A[j]=c
        wa+=A[j]
    print(wa)