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)
    maxv = max(A)

    count_A = [0]*(1000)

    for a in  A:
        count_A[a] += 1

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