n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, c = list(map(int, input().split()))
    index = [i for i, x in enumerate(a_list) if x == b]
    for i in index:
        a_list[i] = c
    print(sum(a_list))