N = int(input())
A = list(map(int, input().split()))
Q = int(input())
i = 0
s = []
while i < Q:
    B, C = map(int, input().split())
    for j in range(len(A)):
        if B == A[j]:
            A[j] = C
    s.append(sum(A))
    i += 1
for i in s:
    print(i)