from collections import Counter
import copy

N = int(input())

target_list = map(int, input().split())
check = [Counter(target_list)]

for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check[index]:
        result = copy.deepcopy(check[index])
        if C in result:
            result[C] = result[C] + result.pop(B)
        else:
            result[C] = result.pop(B)
    else:
        result = copy.deepcopy(check[index])
    check.append(result)
    print(sum([a * b for a, b in result.items()]))
