from collections import*

eval(input());s=sum(A:=list(map(int,input().split())));A=Counter(A)

for i in range(int(eval(input()))):b,c=list(map(int,input().split()));s+=(c-b)*A[b];A[c]+=A[b];A[b]=0;print(s)
from collections import*

_,A,_,*Q=[list(map(int,l.split()))for l in open(0)];A=[a for a in A];s=sum(A);C=Counter(A)

for b,c in Q:s+=(c-b)*C[b];C[c]+=C[b];C[b]=0;print(s)
from collections import *

eval(input())
s = sum(A := list(map(int, input().split())))
A = Counter(A)
for i in range(int(eval(input()))):
    b, c = list(map(int, input().split()))
    s += (c - b) * A[b]
    A[c] += A[b]
    A[b] = 0
    print(s)

from collections import *

_, A, _, *Q = [list(map(int, l.split())) for l in open(0)]
A = [a for a in A]
s = sum(A)
C = Counter(A)
for b, c in Q:
    s += (c - b) * C[b]
    C[c] += C[b]
    C[b] = 0
    print(s)

-eval(input()) -s = sum(A := list(map(int, input().split()))) -A = Counter(A) -for i in range(int(eval(input()))): -    b, c = list(map(int, input().split())) -    s += (c - b) * A[b] -    A[c] += A[b] -    A[b] = 0 +_, A, _, *Q = [list(map(int, l.split())) for l in open(0)] +A = [a for a in A] +s = sum(A) +C = Counter(A) +for b, c in Q: +    s += (c - b) * C[b] +    C[c] += C[b] +    C[b] = 0