#D
def sumdic(dic):
    tmp = 0
    for i in dic:
        tmp += int(i)*dic[i]
    print(tmp)
N = int(input())
A = list(map(int, input().split()))
num = {}
for i in A:
    if i in num:
        num[i] += 1
    else:
        num[i] = 1
#print(num)

Q = int(input())
for j in range(Q):
    B, C = map(int, input().split())
    if B in num and C not in num:
        num[C] = num[B]
        del num[B]
    if B in num and C in num:
        num[C] += num[B]
        del num[B]
    #print(num)
    sumdic(num)
#print(num)