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