N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = [[int(j) for j in input().split()] for i in range(Q)]

newList = A
total = sum(newList)
for i in L:
  if i[0] in newList:
    newList = [int(str(s).replace(str(i[0]), str(i[1]))) for s in newList]
    total = sum(newList)
    print(total)
  else:
    print(total)