N=int(input())
A=list(map(int,input().split()))
Q=int(input())
for i in range(1,Q+1):
    B,C = map(int,input().split())
    for word in A:
        if word == B:
            A[A.index(word)] = C
    print(sum(A))
    
