N = int(input())

seq = [int(x) for x in input().split()]
Q = int(input())
d = []
somme = []
e = []
a=b=0
for i in range(Q):
    a,b = [int(x) for x in input().split()]
    if a in seq:
        e = [ b if x == a else x for x in seq][:]
    else:
        e = seq[:]
    somme.append(sum(e))
    seq.clear()
    seq = e[:]
    e.clear()
for i in somme:
    print(i)