# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = list()
C = list()
for i in range(Q):
  b, c = map(int, input().split())
  B.append(b)
  C.append(c)
sorted(A)
A_sum = sum(A)

break_flg = False
for i in range(Q):
  count = 0
  break_flg = False
  bi = B[i]
  ci = C[i]
  for j in range(len(A)):
    ai = A[j]
    if bi == ai:
      A[j] = C[i]
      break_flg = True
      count += 1
    
    if (bi != ai or j == len(A)-1) and break_flg == True:
      A_sum += (count * (ci - bi))
      print(A_sum)
      break
    elif break_flg == False and j == len(A)-1:
      print(A_sum)