# input
N = int(input())
A = list(map(int, input().split()))

Q = int(input())
BC = [tuple(map(int, input().split())) for q in range(Q)]

# check
for before, after in BC:
    if before in A:
        A = [after if a == before else a for a in A]
    print(sum(A))