N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

# print(N)
# print(A)
# print(Q)
# print(B)
# print(C)

ans = []

for i in range(Q):
    for j in range(N):
        if A[j] == B[i]:
            A[j] = C[i]

    ans_item = sum(A)
    ans.append(ans_item)


# print(ans)
for item in ans:
    print(item)
