N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

for i in que:
    for j in range(N):
        if arr[j] == i[0]:
            arr[j] = i[1]
    print(sum(arr))
