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

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

    for j in range(N):

        try:
            idx = A.index(B)
            A[idx]=C
        except ValueError:
            break
    
    print(sum(A))
