import collections
#入力
N = int(input())
Alist = list(map(int,input().split()))
Q = int(input())
Blist = []
Clist = []
for i in range(Q):
  B, C = map(int,input().split())
  Blist.append(B)
  Clist.append(C)

Adic = collections.Counter(Alist)

def dicsum(dic):
  sum = 0
  for i in range(len(dic)):
    sum += list(dic.keys())[i]*list(dic.values())[i]
  return sum


for j in range(Q):
  if (Blist[j] in Adic) == True:
    Adic[Clist[j]] += Adic[Blist[j]] 
    Adic.pop(Blist[j])
    print(dicsum(Adic))
  else:
    print(dicsum(Adic))