#Take value of N
#Take all value of A
#Take Q, the number of time operation occur
#Take value x and y and append it on B and C
#using while loop, replace the value of A[counter] that's equal to B with C
#calculate the sum and then print the value

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

counter = 0

while counter<Q:
    x, y = map(int, input().split(" "))
    B.append(x)
    C.append(y)
    counter += 1

counter = 0
counter2 = 0

while counter2<Q:
    while counter<N:
        if A[counter] != B[counter2]:
            counter += 1
            continue
        else:
            A[counter] = C[counter2]
            continue

        
    total = 0
    finalcounter = 0
    while finalcounter<N:
        total = total + A[finalcounter]
        finalcounter += 1
    print(total)
    counter = 0
    counter2 += 1