N = int(input())
A = [0]*N
A = list(map(int,input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = map(int,input().split())


S = [0]*Q
for i in range(Q):
    for j in range(N):
        if A[j] == B[i]:
            A[j] = C[i]
    for k in range(N):
        S[i] += A[k] 

for i in range(Q):
    print(S[i])