N=int(input())
A = list(map(int,input().split()))
Q=int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i]=map(int,input().split())
ls = []
lsans=[]
D = A
for j in range(Q):
    ans = 0
    #print(ls)
    ls.append([a for a,x in enumerate(A) if x == B[j]])
    #print(B[j])
    #print(B)
    #print([a for a,x in enumerate(A) if x == B[j]])
    for i in range(len(ls[j])):
        D[ls[j][i]] = C[j]
    for z in range(N):
        ans += D[z]
        D = A
    lsans.append(ans)
for i in range(len(lsans)):
    print (lsans[i])
