def getCalc(AAA, BBB):
    sum = 0
    for i in range(len(AAA)):
        sum += AAA[i] * BBB[i]
    return sum


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

AAA = []
BBB = []

for i in range(10 ** 5 + 1):
    count = A.count(i)
    if (count > 0):
        AAA.append(i)
        BBB.append(count)

total = getCalc(AAA, BBB)

for i in range(Q):
    if (B[i] in AAA):
        index = AAA.index(B[i])

        if(C[i] in AAA):
            Cindex = AAA.index(C[i])
            AAA[index] = C[i]
            BBB[index] += BBB[Cindex]
            AAA.pop(Cindex)
            BBB.pop(Cindex)
        else:
            AAA[index] = C[i]

        total = getCalc(AAA, BBB)

    print(total)
