N = int(input().strip())
A = list(map(int, input().strip().split()))
Q = int(input())
BC = [list(map(int, input().strip().split())) for q in range(Q)]

for bc in BC:
    A = [a if a != bc[0] else bc[1] for a in A]
    print(sum(A))