n = int(input())
a = list(map(int,input().split()))
b = {}
for x in a:
  try:
    if b[x]:
      b[x] += 1
  except:
    b[x] = 1
#print(b)
ans = sum(a)
q = int(input())
for _ in range(q):
  x,y = map(int,input().split())
  try:
    if b[x] != -1:
      bx = b[x]
      b[x] = 0
  except:
    #print(b)
    print(ans)
    continue
  try:
    if b[y]:
      b[y] += bx
  except:
    b[y] = bx
  #print(b)
  ans += bx * (y-x)
  print(ans)