import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
Q = int(input())
#cnt = 0
#cnt += 1

ans = sum(A)
D = [0,]*100000
for i in range (100000):
    D[i] = A.count(i)

for _ in range(Q):
    B,C = map(int, input().split())
    if D[B] > 0:
        ans += D[B]*(C-B)
        D[C] += D[B]
        D[B] = 0
    #print(D[0:10])
    print(ans)
