a=int(input())
l=list(map(int,input().split()))
b=int(input())
grand=0
for i in range(b):
  sum=0
  l1=list(map(int,input().split()))
  for i in range(len(l)):
    if l[i] ==l1[0]:
      l[i]=l1[1]
    sum+=l[i]
  print(sum)