n= int(input())
a = [int(x) for x in input().split()]
q =int(input())
n= sum(a)


for i in range(q):
    n = sum(a)
    b,c=map(int,input().split())
    print(n + a.count(b)*(c-b))
    a.sort()
    while b in a:
        a[a.index(b)]=c




