n = int(input())
arr = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(0,q):
  bi, ci = list(map(int, input().split()))
  b.append(bi)
  c.append(ci)
for i in range(0, len(b)):
  if b[i] in arr:
      for j in arr:
          if j == b[i]:
              ind = arr.index(b[i])
              arr[ind] = c[i]
  print(sum(arr))
    
