n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    a = [c if a[i] == b else a[i] for i in range(len(a))]
    print(sum(a))
