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


for s in S:
    print(s)