n = int(input())
als = list(map(int,input().split()))
ans = sorted(als)
q = int(input())
for i in range(q):
    b, c = map(int,input().split())
    if b in ans:
        ans =[ans[j] if ans[j] != b else c for j in range(n)]        
    print(sum(ans))