n=int(input())
l=[]
a,*b=map(int,input().split())
l.append(a)
for i in range(len(b)):
    l.append(b[i])
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 k in range(len(l)):
        if b[j]==l[k]:
            l.remove(l[k])
            l.insert(k,c[j])
            print(sum(l))
  