# coding: utf-8

N = int(input())
A = list(map(int, input().split()))

Q = int(input())

B = []
C = []

sums = []
for i in range(Q):
    A = sorted(A)
    b, c = list(map(int, input().split()))
    A = [c if a == b else a for a in A] 
    sums.append(sum(A))
    
for s in sums:
    print(s)
