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

q = int(input())
BCs = []
for i in range(0, q):
  b, c = list(map(int, input().split()))
  BCs.append([b, c])

for b, c in BCs:
  sum = 0
  for i in range(0, len(a)):
    if a[i] == b:
      a[i] = c
    sum += a[i]
  print(str(sum))