import sys, math

def calcSum(AList, B, C, Sum):
    Len = AList[B]
    Sum += (C-B) * Len

    AList[B] = 0
    AList[C] += Len
    return Sum

if(__name__ == "__main__"):

    

    N= int( input().strip() )

    Max = 10**5
    AList = [0] * Max
    A_str = input().strip().split()
    N_Queries = int( input().strip() )

    sum = 0
    for i in range(N):
        value = int(A_str[i])
        AList[value] += 1
        sum += value
    BCs = []
    for i in range(N_Queries):
        BC_str =  input().strip().split()
        BC = [ int(BC_str[0]), int(BC_str[1]) ]
        BCs.append(BC)

    for i in range(N_Queries):
        B= BCs[i][0]
        C= BCs[i][1]
        sum = calcSum(AList, B, C, sum)
        print(sum)
