count =int(input())
nums=[]
nums=input().split(" ")
count2=int(input())

nums2=[]
for i in range(count):
    nums2.append(int(nums[i]))
#print(nums2)
#if nums2[0]==1:
#    nums2[0]=10
#print(nums2)

totals=[]
for i in range(count2):
    nums3=[]
    nums3=input().split(" ")
    num1=int(nums3[0])
    num2=int(nums3[1])
    #print(num1,num2)
    total=0
    for k in range(count):
        #print(nums2[k])
        if nums2[k]==num1:
            #print("a")
            nums2[k]=num2
        total=total+nums2[k]
        if k == count-1:
            totals.append(total)
            #print(nums2)
            

#print(totals)
for i in range(len(totals)):
    print(totals[i])
