n = int(input())
a = list(map(int, input().split()))
q = int(input())
bclist = [[0] for i in range(q)]
ans = []

for i in range(q):
    count = 0
    b, c = map(int, input().split())

    for j in a:
        if j == b:
            a[count] = c
        count += 1
    a_list = [_ for _ in a]
    ans.append(a_list)

for answer in ans:
    print(sum(answer))