_ = input()
s = list(map(int, input().split()))
n = int(input())
list_ = []
for _ in range(n):
  k,v = map(int, input().split())
  list_.append({k:v})

for maps in list_:
  k=list(maps.keys())[0]
  v=list(maps.values())[0]
  for i in range(len(s)): 
    if s[i]==k:
      s[i] = v
  ans = 0
  for num in s:
    ans += int(num)
  print(ans)

