from collections import Counter



N = int(eval(input()))

A = list(map(int, input().split()))

Q = int(eval(input()))

X = [list(map(int, input().split())) for _ in range(Q)]



ctr = Counter(A)

ans = sum(A)

for b, c in X:

    v = ctr[b]

    ans = ans - b * v + c * v

    ctr[b] -= v

    ctr[c] += v

    print(ans)



from collections import Counter



N = int(eval(input()))

X = list(map(int, input().split()))

Q = int(eval(input()))

Y = [list(map(int, input().split())) for _ in range(Q)]



ctr = Counter(X)

ans = sum(X)

for b, c in Y:

    n = ctr[b]

    ctr[b] = 0

    ctr[c] += n

    ans = ans - b * n + c * n

    print(ans)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(A)
ans = sum(A)
for b, c in X:
    v = ctr[b]
    ans = ans - b * v + c * v
    ctr[b] -= v
    ctr[c] += v
    print(ans)

from collections import Counter

N = int(eval(input()))
X = list(map(int, input().split()))
Q = int(eval(input()))
Y = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(X)
ans = sum(X)
for b, c in Y:
    n = ctr[b]
    ctr[b] = 0
    ctr[c] += n
    ans = ans - b * n + c * n
    print(ans)

-A = list(map(int, input().split())) +X = list(map(int, input().split())) -X = [list(map(int, input().split())) for _ in range(Q)] -ctr = Counter(A) -ans = sum(A) -for b, c in X: -    v = ctr[b] -    ans = ans - b * v + c * v -    ctr[b] -= v -    ctr[c] += v +Y = [list(map(int, input().split())) for _ in range(Q)] +ctr = Counter(X) +ans = sum(X) +for b, c in Y: +    n = ctr[b] +    ctr[b] = 0 +    ctr[c] += n +    ans = ans - b * n + c * n