N = int(input())

target_list = list(map(int, input().split()))
result = []

for i in range(int(input())):
    B, C = map(int, input().split())
    if B in target_list:
        num = target_list.count(B)
        target_list = [x for x in target_list if x != B]
        target_list.extend([C] * num)
        result.append(sum(target_list))
    else:
        result.append(sum(target_list))

for i in result:
    print(i)
