n = int(input())
list_a = list(map(int, input().split()))
q = int(input())
ans = sum(list_a)

for i in range(q):
    b, c = map(int, input().split())
    count = list_a.count(b)
    list_a = [c if i == b else i for i in list_a]
    ans += count * (c-b)

    print(ans)
