n = int(input())
A = list(map(int, input().split()))
q = int(input())
bc = []
for _ in range(q):
    bc.append(list(map(int, input().split())))
    
for i in range(q):
    for j, a in enumerate(A):
        if a == bc[i][0]:
            A[j] = bc[i][1]
    print(sum(A))