N=int(input())
A=list(map(str,(input().split())))
Q=int(input())
B=[]
C=[]
for _ in range(Q):
  L, R = map(str,(input().split()))
  B.append(L)
  C.append(R)

for i in range(Q):
  A_string = ",".join(A)
  A_new = A_string.replace(B[i],C[i])
  A =  A_new.split(",")
  int_A =map((lambda x: int(x)), A)
  print(sum(int_A))