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())
#print(B,C)
#print(A)
#a = 0
#for i in range(N):
    #a += A[i]
#print(a)
for j in range(Q):
    a = 0
    for i in range(N):
        if A[i] == B[j]:
            #a = a + (C[j]-A[i])
            a += C[j]
            A[i] = C[j]
            #print(A)
        else:
            a += A[i]
            #print(A)
    #print(A)
    print(a)
