N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = []
for _ in range(Q):
    b, c = map(int, input().split())
    if b in A:
        for n in range(N):
            if A[n] == b:
                A[n] = c
    ans.append(sum(A))
    
for q in range(Q):
    print(ans[q])