N = input()
AT = input()
Q = input()
BT = []

N = int(N)
A = AT.split(" ")
Q = int(Q)

for i in range(N):
    A[i] = int(A[i])

sum = 0
out = []

for i in range(Q):
    X = input()
    B = X.split(" ")
    B[0] = int(B[0])
    B[1] = int(B[1])

    for j in range(N):
        if A[j] == B[0]:
            A[j] = B[1]
        sum = sum + A[j]
    out.append(sum)
    sum = 0

for i in range(len(out)):
    print(out[i])

