N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [list(map(int,input().split())) for _ in range(Q)]
for k in range(Q):    
    A = [B[k][1] if B[k][0]==i else i for i in A]
    print(sum(A))