n = int(input())
als = list(map(int,input().split()))
ans = sorted(als)
ans02 = []
cot = 0
q = int(input())
for i in range(q):
    b, c = map(int,input().split())
    if b in ans:
      cot = ans.count(b) 
      ans02 =[ans02[j] if ans[j] != b else c for j in range(len(ans02))]  
    print(sum(ans)+(c-b)*cot+sum(ans02))