N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    A_list = [C if j == B else j for j in A_list]
    print(sum(A_list))