from collections import Counter
import copy

N = int(input())

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


for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check[index]:
        result = copy.deepcopy(check[index])
        change = result.pop(B)
        diff = change * (C - B)
        if C in result:
            result[C] = result[C] + change
        else:
            result[C] = change

    else:
        result = copy.deepcopy(check[index])
        diff = 0
    check.append(result)
    print(result_list[index] + diff)
    result_list.append(result_list[index] + diff)
