n=int(input()) #get input N
a=list(map(int, input().split())) #get input A
q=int(input()) #get input Q
b=0 #for increment in while loop
c=0 #temporary answer

while b<q: #loop to get input for B and C

    x,y=input().split(" ")
    for i in a:
       if x==i:
           i=y #change element into C

    for i in a:
        c+=i #add all element in list

    print (c)
    b+=1
    c=0