import sys
input = sys.stdin.readline
n= int(input())
alist = list(map(int,input().split()))
q =int(input())

def repr(x,b,c):
  if x==b:
    return c
  else:
    return x
  
for i in range(q):
  b, c = map(int,input().split())
  alist = list(map(lambda x: repr(x,b,c), alist))
  output = sum(alist)
  print(output)