import sys

input_data = []
input_pointer = 0

output_data = []

def input_scan():
    global input_data
    input_data = sys.stdin.readlines()
    input_data = [x[:-1] for x in input_data]

def next_line():
    global input_pointer
    global input_data
    if input_pointer < len(input_data):
        input_pointer += 1
        return input_data[input_pointer - 1]
    else:
        return ""

def append_output(string):
    global output_data
    output_data.append(string)

def print_output():
    global output_data
    output_data.append("")
    sys.stdout.write("\n".join(output_data))

# Problem A
# alpha = input()
# if alpha.isupper():
#     print("A")
# else:
#     print("a")

# Problem B
# input_scan()
# [n, k] = [int(x) for x in next_line().split(" ")]
# fruits = sorted([int(x) for x in next_line().split(" ")])
# print(sum(fruits[:k]))

# Problem C
# num = int(input())

# dictionary = "abcdefghijklmnopqrstuvwxyz"

# def convert_to_alpha(num):
#     if num == 0:
#         return ""
#     quot = num // 26
#     rem = num % 26
#     if rem == 0:
#         return "z" + convert_to_alpha(quot - 1)
#     else:
#         return dictionary[rem - 1] + convert_to_alpha(quot)

# name = ""
# print("".join(reversed(convert_to_alpha(num))))

# Problem D
input_scan()

next_line()
from collections import Counter
nums = [int(x) for x in next_line().split(" ")]
total_sum = sum(nums)
nums = Counter(nums)


q = int(next_line())
for i in range(q):
    [b, c] = [int(x) for x in next_line().split(" ")]
    diff = c - b
    total_sum += nums[b] * diff
    occ = nums[b]
    if c in nums:
        nums[c] += occ
    else:
        nums[c] = occ

    append_output(str(total_sum))

print_output()
