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

BC = []
for i in range(Q):
    B, C = map(int, input().split())
    D = [C if l == B else l for l in A]
    print(sum(D))
    A = D