N=int(eval(input()))

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

TMP=sum(A)

Q=int(eval(input()))

import collections

List=collections.Counter(A)

for i in range(Q):

  S,T=list(map(int,input().split()))  

  TMP=TMP+(T-S)*List[S]

  print(TMP)  

  List[T]+=List[S]

  List[S]=0
def II(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

N=II()

A=LI()

Sum=sum(A)

Q=II()

cnt={}

queries=[]

for i in range(Q):

  b,c=MI()

  queries.append((b,c))

for a in A:

  if a not in cnt:

    cnt[a]=0

  cnt[a]+=1

#print(cnt)   

for b,c in queries:

  if b in cnt:

    Sum-=cnt[b]*b

    Sum+=cnt[b]*c

    if c not in cnt:

      cnt[c]=0

    cnt[c]+=cnt[b]

    cnt[b]=0

  print(Sum) 

  
N = int(eval(input()))
A = list(map(int, input().split()))
TMP = sum(A)
Q = int(eval(input()))
import collections

List = collections.Counter(A)
for i in range(Q):
    S, T = list(map(int, input().split()))
    TMP = TMP + (T - S) * List[S]
    print(TMP)
    List[T] += List[S]
    List[S] = 0

def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


N = II()
A = LI()
Sum = sum(A)
Q = II()
cnt = {}
queries = []
for i in range(Q):
    b, c = MI()
    queries.append((b, c))
for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1
# print(cnt)
for b, c in queries:
    if b in cnt:
        Sum -= cnt[b] * b
        Sum += cnt[b] * c
        if c not in cnt:
            cnt[c] = 0
        cnt[c] += cnt[b]
        cnt[b] = 0
    print(Sum)

-N = int(eval(input())) -A = list(map(int, input().split())) -TMP = sum(A) -Q = int(eval(input())) -import collections +def II(): +    return int(eval(input())) -List = collections.Counter(A) + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +N = II() +A = LI() +Sum = sum(A) +Q = II() +cnt = {} +queries = [] -    S, T = list(map(int, input().split())) -    TMP = TMP + (T - S) * List[S] -    print(TMP) -    List[T] += List[S] -    List[S] = 0 +    b, c = MI() +    queries.append((b, c)) +for a in A: +    if a not in cnt: +        cnt[a] = 0 +    cnt[a] += 1 +# print(cnt) +for b, c in queries: +    if b in cnt: +        Sum -= cnt[b] * b +        Sum += cnt[b] * c +        if c not in cnt: +            cnt[c] = 0 +        cnt[c] += cnt[b] +        cnt[b] = 0 +    print(Sum)