f=lambda:list(map(int,input().split()))

f()

s,*l=[0]*100002

for i in f(): s+=i; l[i]+=1

q,=f()

for _ in range(q): b,c=f(); s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s)
n,*L=list(map(int,open(0).read().split()))

A,q,Q=L[:n],L[n],L[n+1:]

s,*l=[0]*100002

for i in A: s+=i; l[i]+=1

for b,c in zip(*[iter(Q)]*2): s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s)
f = lambda: list(map(int, input().split()))
f()
s, *l = [0] * 100002
for i in f():
    s += i
    l[i] += 1
(q,) = f()
for _ in range(q):
    b, c = f()
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

n, *L = list(map(int, open(0).read().split()))
A, q, Q = L[:n], L[n], L[n + 1 :]
s, *l = [0] * 100002
for i in A:
    s += i
    l[i] += 1
for b, c in zip(*[iter(Q)] * 2):
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

-f = lambda: list(map(int, input().split())) -f() +n, *L = list(map(int, open(0).read().split())) +A, q, Q = L[:n], L[n], L[n + 1 :] -for i in f(): +for i in A: -(q,) = f() -for _ in range(q): -    b, c = f() +for b, c in zip(*[iter(Q)] * 2):