n=int(input())

a=list(map(int,input().split()))

q=int(input())
b=[]
d=[]
for i in range(q):
    t,p=map(int,input().split())
    b.append(t)
    d.append(p)

for k in range(q):
    l=[i for i, x in enumerate(a) if x == b[k]]
    for j in l:
        a[j]=d[k]
    print(sum(a))
