if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B = []
    C = []

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

    sum_num = sum(A)

    count_A = dict() 
    setA = set(A)
    for s in  setA:
        count_A[s] = A.count(s) 

    for i in range(Q):
        inc = (C[i]-B[i])*count_A[B[i]]
        if not(C[i] in count_A):
            count_A[C[i]] = 0
        count_A[C[i]] += count_A[B[i]]
        sum_num += inc
        print(sum_num)