N = int(input())

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

Q = int(input())
 
for i in range(Q+1):
    b, c = map(int, input().split())

    A_replace = [c if j == b else j for j in A]

    A = A_replace

    print(sum(A_replace))

