n=int(input())
a=list(map(int,input().split()))
t=int(input())
a=sorted(a)
for i in range(t):
    d,c=map(int,input().split())
    while(d in a):
     index = a.index(d)
     a[index]=c  
    print(sum(a))