n = int(input())
a = list(map(int, input().split()))

dicts = {}
for tmp in a:
  if tmp in dicts.keys():
    dicts[tmp] += 1
  else:
    dicts[tmp] = 1
    
m = int(input())
result = 0
for key, value in dicts.items():
  result += key*value

for _ in range(m):
  b,c = list(map(int, input().split()))
  if b in dicts.keys():
    tmp = dicts[b]
    del dicts[b]
    if c in dicts.keys():
      dicts[c] += tmp
    else:
      dicts[c] = tmp
    result = 0
    for key, value in dicts.items():
      result += key*value
    print(result)
  else:
    print(result)
  