def getCalc(NUM, num_list):
    sum = 0
    for i in num_list:
        sum += i * NUM[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)

max_num = max(max(A), max(B), max(C))

NUM = [0] * (max_num + 1)

num_list = []

for a in A:
    NUM[a] += 1
    num_list.append(a)

for i in range(Q):
    if(B[i] in num_list):
        NUM[B[i]], NUM[C[i]] = 0, NUM[B[i]] + NUM[C[i]]
        num_list.remove(B[i])
        num_list.append(C[i])

    print(getCalc(NUM, num_list))
