import sys
input = sys.stdin.readline

nums = {}
n = int(input())
li = list(map(int,input().split()))
q = int(input())
BC = []
for _ in range(q):
    b, c = map(int,input().split())
    BC.append([b, c])

for i in range(n):
    if li[i] in nums:
        nums[li[i]] += 1
    else:
        nums[li[i]] = 1

for i in range(q):
    if BC[i][0] in nums:
        if BC[i][1] in nums:
            nums[BC[i][1]] += nums[BC[i][0]]
            nums[BC[i][0]] = 0
        else:
            nums[BC[i][1]] = nums[BC[i][0]]
            nums[BC[i][0]] = 0
    s = 0
    for i in nums.keys():
        s += nums[i]*i
    print(s)