N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)] #
B, C = [list(i) for i in zip(*BC)]

for i in range(0, Q):
    A = [C[i] if j == B[i] else j for j in A]
    print(sum(A))