N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]


for nums in B:
    A = [nums[1] if i == nums[0] else i for i in A]
    print(sum(A))
