n=int(input(""))
ain=input("").split(" ")
a=[]
for i in range(n):
    a+=[int(ain[i])]
q=int(input(""))
c=[]
listb=[]
listc=[]
for i in range(q):
    c+=[input("").split(" ")]
    listb+=[int(c[i][0])]
    listc+=[int(c[i][1])]
    for k in range(n):
        if (a[k]==listb[i]):
            a[k]=listc[i]
    print(sum(a))
    

    
