N = int(input())
A = list(map(int, input().split()))
Q = int(input())
num = [0 for i in range(100000)]
ans = sum(A)

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