import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

import collections
counter = collections.defaultdict(int)
for key, value in collections.Counter(A).items():
    counter[key] = value

ans = sum(A)

for _ in range(Q):
    b, c = map(int, input().split())
    # print("b: {} c: {} counter: {}".format(b, c, counter))
    v = counter[b]
    counter[c] += v
    dif = v * (c - b)
    ans += dif
    print(ans)