import collections

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()))
    c_list = collections.Counter(now_list)
    index = trial[0]
    total += (trial[1] - trial[0]) * int(c_list[index])
    print(total)
    
    now_list = [trial[1] if i == trial[0] else i for i in now_list]