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 k, word in enumerate(A):
        if word == B:
            A[k] = C
    print(sum(A))
    
