N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

ans = sum(A)
d = dict()
for i in range(N):
    if A[i] not in d:
        d[A[i]] = set()
    d[A[i]].add(i)

for i in range(Q):
    if B[i] not in d:
        print(ans)
        continue
    size = len(d[B[i]])
    sa = C[i]-B[i]
    if C[i] not in d:
        d[C[i]] = set()
    d[C[i]] = d[C[i]] | d[B[i]]
    d[B[i]] = set()
    ans += size * sa
    print(ans)