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=[]
#ls.append([i for i,x in enumerate(A) if x == 2])
D = A
for j in range(Q):
    #print(Q)
    #print(D)
    ans = 0
    ls.append([a for a,x in enumerate(A) if x == B[j]])
    #print(B[j],"B[j]")
    #print("j=",j,[a for a,x in enumerate(A) if x == B[j]])
    #print(A)
    if len(ls[j]) != 0:
        for i in range(len(ls[j])):
            #print("i",i)
            #print(len(ls[j]))
            #print(A)
            D[ls[j][i]] = C[j]
            #print(D)
        for z in range(N):
            ans += D[z]
            D = A
                #print("ans",ans)
            #lsans = []
        lsans.append(ans)
        #print("j",j)
            #print(lsans)
for i in range(len(lsans)):
    print (lsans[i])
