import bisect

import copy

import heapq

import math

import sys

from collections import *

from functools import lru_cache

from itertools import accumulate, combinations, permutations, product

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

sys.setrecursionlimit(500000)

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



n=int(eval(input()))

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

q=int(eval(input()))

bc=[list(map(int,input().split())) for i in range(q)]



lst=[0]*(10**5+1)

ans=0

for i in range(n):

    lst[a[i]]+=1

    ans+=a[i]

# print(ans)



for i in range(q):

    b,c=bc[i]

    bcnt=lst[b]

    ans+=(c-b)*bcnt

    lst[c]+=bcnt

    lst[b]=0

    print(ans)
import bisect

import copy

import heapq

import math

import sys

from collections import *

from functools import lru_cache

from itertools import accumulate, combinations, permutations, product

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

sys.setrecursionlimit(500000)

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



# n=int(input())

# a=list(map(int,input().split()))

# q=int(input())

# bc=[list(map(int,input().split())) for i in range(q)]



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

 

n = int(readline())

a = tuple(map(int, readline().split()))

q = int(readline())

m = list(map(int, read().split()))



lst=[0]*(10**5+1)

ans=0

for i in range(n):

    lst[a[i]]+=1

    ans+=a[i]

# print(ans)



for b, c in zip(m, m):

    bcnt=lst[b]

    ans+=(c-b)*bcnt

    lst[c]+=bcnt

    lst[b]=0

    print(ans)

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


sys.setrecursionlimit(500000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
bc = [list(map(int, input().split())) for i in range(q)]
lst = [0] * (10**5 + 1)
ans = 0
for i in range(n):
    lst[a[i]] += 1
    ans += a[i]
# print(ans)
for i in range(q):
    b, c = bc[i]
    bcnt = lst[b]
    ans += (c - b) * bcnt
    lst[c] += bcnt
    lst[b] = 0
    print(ans)

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


sys.setrecursionlimit(500000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
# n=int(input())
# a=list(map(int,input().split()))
# q=int(input())
# bc=[list(map(int,input().split())) for i in range(q)]
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
a = tuple(map(int, readline().split()))
q = int(readline())
m = list(map(int, read().split()))
lst = [0] * (10**5 + 1)
ans = 0
for i in range(n):
    lst[a[i]] += 1
    ans += a[i]
# print(ans)
for b, c in zip(m, m):
    bcnt = lst[b]
    ans += (c - b) * bcnt
    lst[c] += bcnt
    lst[b] = 0
    print(ans)

-n = int(eval(input())) -a = list(map(int, input().split())) -q = int(eval(input())) -bc = [list(map(int, input().split())) for i in range(q)] +# n=int(input()) +# a=list(map(int,input().split())) +# q=int(input()) +# bc=[list(map(int,input().split())) for i in range(q)] +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +n = int(readline()) +a = tuple(map(int, readline().split())) +q = int(readline()) +m = list(map(int, read().split())) -for i in range(q): -    b, c = bc[i] +for b, c in zip(m, m):