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

sum = sum(a)

for i in bc:
    b = i[0]
    c = i[1]
    count = a.count(b)
    a = [c if i==b else i for i in a]
    sum += count*(c-b)
    # print(a)
    print(sum)