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

for q in range(Q):
    B,C = map(int,input().split())
    for a in range(len(A)):
        if A[a] == B:
            A[a] = C
    result.append(sum(A))
[print(i) for i in result] 