N=int(eval(input()))

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

Q=int(eval(input()))

D=dict()

s=0

for i in A:

  s+=i

  if i in D:

    D[i]+=1

  else:

    D[i]=1

for _ in range(Q):

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

  if b in D:

    s+=(c-b)*D[b]

    if c in D:

      D[c]+=D[b]

    else:

      D[c]=D[b]

    del D[b]

  print(s)
import sys

from collections import Counter

readline=sys.stdin.readline

n=readline()

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

q=int(readline())

D=Counter(A)

s=sum(A)

for _ in range(q):

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

  s+=(c-b)*D[b]

  D[c]+=D[b]

  del D[b]

  print(s)
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
D = dict()
s = 0
for i in A:
    s += i
    if i in D:
        D[i] += 1
    else:
        D[i] = 1
for _ in range(Q):
    b, c = list(map(int, input().split()))
    if b in D:
        s += (c - b) * D[b]
        if c in D:
            D[c] += D[b]
        else:
            D[c] = D[b]
        del D[b]
    print(s)

import sys
from collections import Counter

readline = sys.stdin.readline
n = readline()
A = list(map(int, readline().split()))
q = int(readline())
D = Counter(A)
s = sum(A)
for _ in range(q):
    b, c = list(map(int, readline().split()))
    s += (c - b) * D[b]
    D[c] += D[b]
    del D[b]
    print(s)

-N = int(eval(input())) -A = list(map(int, input().split())) -Q = int(eval(input())) -D = dict() -s = 0 -for i in A: -    s += i -    if i in D: -        D[i] += 1 -    else: -        D[i] = 1 -for _ in range(Q): -    b, c = list(map(int, input().split())) -    if b in D: -        s += (c - b) * D[b] -        if c in D: -            D[c] += D[b] -        else: -            D[c] = D[b] -        del D[b] +import sys +from collections import Counter + +readline = sys.stdin.readline +n = readline() +A = list(map(int, readline().split())) +q = int(readline()) +D = Counter(A) +s = sum(A) +for _ in range(q): +    b, c = list(map(int, readline().split())) +    s += (c - b) * D[b] +    D[c] += D[b] +    del D[b]