N=int(input())  # Read N Number of integers 
A = list(map(int,input().split()))  # read the sequence of A
Q=int(input()) # read Q from user
 
for i in range(Q):
    B,C = map(int,input().split()) # read B and C from user
    for j in range(N):
        if A[int(j)] == B:
            A[int(j)]=C
    print(sum(A)) # print the result