import bisect

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

ans1 =  sum(a)
ans2 =  ans1

for i in range(Q):
    ans1 = ans2
    B,C = map(int, input().split())
    a.sort()
    cnt = a.count(B)
    if cnt == N:
        ans1  = C*N
        print(ans1)
        a = [C for k in range(N)]
        continue
        
    
    index = bisect.bisect(a,B)
    for j in range(cnt):
        a[index+j-cnt] = C
        ans2 += C-B

    print(ans2)
    ans1 = ans2


            
    

    