num = int(input())
original = list(map(int, input().split()))
trial_num = int(input())

total = sum(original)
now_list = original

for i in range(trial_num):
    trial = list(map(int, input().split()))
    count = 0
    for i in range(num):
        if now_list[i] == trial[0]:
            now_list[i] = trial[1]
            count += 1
    total += (trial[1] - trial[0]) * count
    print(total)
    