N = int(input())

A = list(map(int, input().split()))

Q = int(input())

Anslist = [0] * Q

for i in range(Q):

    b, c = map(int, input().split())

    A_replace = [c if j == b else j for j in A]

    A = A_replace
    
    Anslist[i] += sum(A_replace)

for k in range(Q):
    
    print(Anslist[k])
