N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[]
for i in range(Q):
    B,C=map(int,input().split())
    A_replace=[C if A[j]==B else A[j] for j in range(N)]
    A=A_replace
    print(sum(A_replace))