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