import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
num = [0]*100000
s = sum(A)
for i in range(max(A)):
    num[i] = A.count(i+1)
for i in range(Q):
    B, C = map(int,input().split())
    s += (C-B)*num[B-1]
    print(s)
    num[C-1] += num[B-1]
    num[B-1] = 0