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 n,i in enumerate(l):
        if b[j]==i:
            l[n]=c[j]
    print(sum(l))
  