import collections

_ = eval(input())

a = [*list(map(int, input().split()))]

q = int(eval(input()))

s = sum(a)

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

c = collections.Counter(a)

for i,j in b:

    if j not in c:

        c[j] = 0

    if i not in c:

        c[i] = 0

    s += (j-i)*c[i]

    c[j]+=c[i]

    c[i] = 0

    print(s)
from collections import defaultdict

_ = eval(input())

a = [*list(map(int, input().split()))]

q = int(eval(input()))

s = sum(a)

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

c = defaultdict(int)

for i in a:

    c[i]+=1

for i,j in b:

    s += (j-i)*c[i]

    c[j]+=c[i]

    c[i] = 0

    print(s)
import collections

_ = eval(input())
a = [*list(map(int, input().split()))]
q = int(eval(input()))
s = sum(a)
b = [[*list(map(int, input().split()))] for _ in range(q)]
c = collections.Counter(a)
for i, j in b:
    if j not in c:
        c[j] = 0
    if i not in c:
        c[i] = 0
    s += (j - i) * c[i]
    c[j] += c[i]
    c[i] = 0
    print(s)

from collections import defaultdict

_ = eval(input())
a = [*list(map(int, input().split()))]
q = int(eval(input()))
s = sum(a)
b = [[*list(map(int, input().split()))] for _ in range(q)]
c = defaultdict(int)
for i in a:
    c[i] += 1
for i, j in b:
    s += (j - i) * c[i]
    c[j] += c[i]
    c[i] = 0
    print(s)

-import collections +from collections import defaultdict -c = collections.Counter(a) +c = defaultdict(int) +for i in a: +    c[i] += 1 -    if j not in c: -        c[j] = 0 -    if i not in c: -        c[i] = 0