import bisect

N = int(input())
a = list(map(int,input().split()))
Q = int(input())


for i in range(Q):
    B,C = map(int, input().split())
    a.sort()
    cnt = a.count(B)
    index = bisect.bisect(a,B)
    for j in range(cnt):
        a[index+j-cnt] = C

    print(sum(a))


            
    

    