N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    B.append(b)
    C.append(c)

for b, c in zip(B, C):
    A = list(map(lambda x: c if x == b else x, A))
    ans = sum(A)
    print(ans)