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

B = []
C = []

for q in range(Q):
    _b, _c = list(map(int, input().split()))
    B.append(_b)
    C.append(_c)


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


for i in range(Q):
    b = B[i]
    c = C[i]
    A = replace(A, b, c)
    print(sum(A))