import numpy as np
N=int(input())
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(input())
index=np.array([i for i in range(10**5+1)])
List=np.array([0 for _ in range(10**5+1)])
for a in A:
    List[a]+=1
BList=np.array([0 for _ in range(10**5+1)])
for q in range(Q):
    B,C=map(int,input().split())
    BList[B]+=C-B
    print(np.sum(BList*List)+SUM)