n=int(input())
l=[]
for i in range(n):
  x=int(input())
  l.append(x)
q=int(input())
b=[]
c=[]
for i in range(q):
  y,z=map(int,input().split())
  b.append(y)
  c.append(z)
for j in range(len(b)):
  for i in l:
    if b[j]==i:
      l.replace(i,c[j])
      print(sum(l))
  