def Convert(A, B, C):
    for i in range(len(A)):
        if A[i] == B:
            A[i] = C
    return sum(A)

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

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