N = int(input())
A_ori = list(map(int, input().split()))
Q = int(input())
BC = [[]]*Q
for i in range(Q):
    BC[i] = list(map(int, input().split()))

for j in range(Q):
    res = 0
    A_fake = A_ori
    for k in range(N):
        if A_fake[k] == BC[j][0]:
            A_fake[k] = BC[j][1]
        res += A_fake[k]
    print(res)
