N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    for i in range(N):
        if A[i] == B:
            A[i] = C
            print(sum(A))
