def su(l):
    return sum(l)
t=int(input())
l=[int(x) for x in input().split(" ")]
t=int(input())
while t>0:
   s=0
   a,b= [int(x) for x in input().split(" ")]
   l[:]=[int(x) if x!=a else b for x in l]
   s=su(l)
   t -= 1
   print(s)
