n = int(input())
a = list(map(int, input().split()))
q = int(input())
B = [list(map(int, input().split())) for _ in range(q)]

# print(n,a,q,B)

# from collections import Counter

# _a = Counter()

for (b, c) in B:
    a = [c if x == b else x for x in a]
    print(sum(a))
