N = int(input())
A = list(map(int, input().split()))
Q = int(input())
num=[]
for i in range(10000):
    num.append(A.count(i))

total=sum(A)
for i in range(Q):
    B, C = map(int, input().split())
    numb = num[B]
    num[B] = num[B] - numb
    num[C] = num[C] + numb
    print(total + (C - B) * numb)
    total=total + (C - B) * numb