N = int(input())

AAA = list(map(int, input().split()))

Q = int(input())

for i in range(0, Q):
    BC = list(map(int, input().split()))
    AAA = [BC[1] if m == BC[0] else m for m in AAA]
    print(sum(AAA))
