# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
for i in range(Q):
	proc_append(tuple(input().split()))
	process[i] = tuple(map(int,process[i]))

for b,c in process:
	A.sort()
	if b not in set(A):
		print('not in')
		continue
	for i in range(N):
		if b==A[i]:
			begin = i
			break
	for i in range(begin,N):
		if b!=A[i]:
			end = i-1
			break
	for i in range(begin,end+1):
		A[i] = c
	print(sum(A))