import sys
input =sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
Q = int(input())
 
 
for _ in range(Q):
  B,C = map(int,input().split())
  a = [C if  i == B  else i for i in a]
  print(sum(a))