N = int(input())

Alist = list(map(int,input().split()))
Q = int(input())

Alistreplace = Alist
for i in range(Q):
  B,C = map(int,input().split())
  #print (B)
  #print (C)
  Alistreplace = [C if j==B else j for j in Alistreplace]
  #print (Alistreplace)
  print (sum(Alistreplace))
  