
n = int(input())
A = [int(x) for x in input().split()]#yoko
q = int(input())

ans = [0] * q

ans1 = sum(A)

A = str(A)

for i in range(q):

    b,c = map(int,input().split())

    if str(b) in A:
        ans1 -= b * A.count(str(b))
        ans1 += c * A.count(str(b))
        A = A.replace(str(b),str(c))
        #A = int(A)

    ans[i] = ans1



for i in range(q):
    print(ans[i])
