n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
BC = [[int(i) for i in input().split()] for _ in range(q)]
for i in range(q) :
    b = BC[i][0]
    c = BC[i][1]
    A = [c if i == b else i for i in A]
    print(sum(A))