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

for i in range(Q):
    B, C = map(int, input().split())

    for i in range(A.count(B)):
        A[A.index(B)] = C

    print(sum(A))