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