n = int(input())

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

q = int(input())

ans = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    diff = c - b
    b_num = sum(x == b for x in a)
    a = [c if i == b else i for i in a]
    ans += diff * b_num
    print(ans)