from collections import defaultdict

 

N = int(eval(input()))

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

 

total = sum(raw_numbers)

 

numbers = defaultdict(int)

 

for num in raw_numbers:

    numbers[num] += 1



Q = int(eval(input()))



for i in range(Q):

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

    taken = numbers[a]

    total -= numbers[a]*a

    numbers[b] += numbers[a]

    numbers[a] = 0

    total += taken*b

    print(total)
from collections import defaultdict

 

N = int(eval(input()))

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

Q = int(eval(input()))

 

total = sum(raw_numbers)

 

numbers = defaultdict(int)

 

for num in raw_numbers:

    numbers[num] += 1



for _ in range(Q):

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

    taken = numbers[a]

    total -= numbers[a]*a

    numbers[b] += numbers[a]

    numbers[a] = 0

    total += taken*b

    print(total)
from collections import defaultdict

N = int(eval(input()))
raw_numbers = list(map(int, input().split()))
total = sum(raw_numbers)
numbers = defaultdict(int)
for num in raw_numbers:
    numbers[num] += 1
Q = int(eval(input()))
for i in range(Q):
    a, b = list(map(int, input().split()))
    taken = numbers[a]
    total -= numbers[a] * a
    numbers[b] += numbers[a]
    numbers[a] = 0
    total += taken * b
    print(total)

from collections import defaultdict

N = int(eval(input()))
raw_numbers = list(map(int, input().split()))
Q = int(eval(input()))
total = sum(raw_numbers)
numbers = defaultdict(int)
for num in raw_numbers:
    numbers[num] += 1
for _ in range(Q):
    a, b = list(map(int, input().split()))
    taken = numbers[a]
    total -= numbers[a] * a
    numbers[b] += numbers[a]
    numbers[a] = 0
    total += taken * b
    print(total)

+Q = int(eval(input())) -Q = int(eval(input())) -for i in range(Q): +for _ in range(Q):