def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B = []
    a = sum(A)
    for i in range(1, 10**5):
        B.append(A.count(i))
    for j in range(Q):
        b, c = map(int, input().split())
        a += B[b-1]*(c-b)
        print(a)
        B[c-1] += B[b-1]
        B[b-1] = 0
resolve()