N = int(input().strip())
A = [int(x) for x in input().strip().split(" ")]
Q = int(input().strip())

for q in range(Q):
    B, C = [int(x) for x in input().strip().split(" ")]
    A = [C if a == B else a for a in A]
    print(sum(A))
