n = int(input())
a = sorted(map(int,input().split()))
q = int(input())
b = [0] * q
c = [0] * q

def replace_sum(b,c,a):
 #   ans = 0
  #  a.replace(b,c)
    #ans = sum(a)
    #print(ans)
    for i in range(len(a)):
        if a[i] == b:
            a[i] = c
    return a



for i in range(q):
    b[i],c[i] = map(int,input().split())

for i in range(q):
    #replace(b[i],c[i],a)
#    a.replace(b, c)
 #   ans = sum(a)
  #  print(ans)
    #sum = 0
   # for j in a:
   #     re = j.replace(str(2),str(3))
    #    #a.append(re)
     #   print(j,end = " ")
      #  print(re)
       # sum += int(j)
    a = replace_sum(b[i],c[i],a)
    #sum = int(sum(a))

    print(sum(a))