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

for b, c in zip(B, C):
    A = [a if a != b else c for a in A]
    print(sum(A))