N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q

for j in range(Q):
    B[j], C[j] = map(int, input().split())
    for k, _ in enumerate(A):
        if _ == B[j]:
            A[k] = C[j]
    print(sum(A))