from collections import Counter

n = int(eval(input()))

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

l = Counter(a)

q = int(eval(input()))

ans = sum(a)



for _ in range(q):

    b,c = list(map(int, input().split()))

    tmp = l[b]

    l[c] += tmp

    l[b] = 0

    ans += (c-b) * tmp

    print(ans)
from collections import Counter

n = int(eval(input()))

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

a = Counter(A)

q = int(eval(input()))

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



ans = sum(A)

for b,c in bc:

    ans -= b*a[b]

    ans += c*a[b]

    if b in a:

        if c in a: a[c] += a[b]

        else: a[c] = a[b]

        a.pop(b)

    print(ans)
from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
l = Counter(a)
q = int(eval(input()))
ans = sum(a)
for _ in range(q):
    b, c = list(map(int, input().split()))
    tmp = l[b]
    l[c] += tmp
    l[b] = 0
    ans += (c - b) * tmp
    print(ans)

from collections import Counter

n = int(eval(input()))
A = list(map(int, input().split()))
a = Counter(A)
q = int(eval(input()))
bc = [list(map(int, input().split())) for _ in range(q)]
ans = sum(A)
for b, c in bc:
    ans -= b * a[b]
    ans += c * a[b]
    if b in a:
        if c in a:
            a[c] += a[b]
        else:
            a[c] = a[b]
        a.pop(b)
    print(ans)

-a = list(map(int, input().split())) -l = Counter(a) +A = list(map(int, input().split())) +a = Counter(A) -ans = sum(a) -for _ in range(q): -    b, c = list(map(int, input().split())) -    tmp = l[b] -    l[c] += tmp -    l[b] = 0 -    ans += (c - b) * tmp +bc = [list(map(int, input().split())) for _ in range(q)] +ans = sum(A) +for b, c in bc: +    ans -= b * a[b] +    ans += c * a[b] +    if b in a: +        if c in a: +            a[c] += a[b] +        else: +            a[c] = a[b] +        a.pop(b)