import numpy as np

def sum(n, a):
  ans = 0
  n = int(n)
  for num in range(n):
    ans += int(a[num])
  print(ans)

n = input()
a = [e for e in input().split()]
q = input()
q = int(q)

# b = np.zeros((q, 2), dtype=int)

for num in range(q):
  # b[num][0],b[num][1] = input().split()
  b1,b2 = input().split()
  a = [s.replace(b1,b2) for s in a]
  sum(n,a)


# for num in range(q):
#   a = [s.replace(str(b[num][0]),str(b[num][1])) for s in a]
#   sum(n,a)
#   # print(int(a[0]) + int(a[1]) + int(a[2]) + int(a[3]) )

