n=int(input())
a=list(map(int,input().split()))
q=int(input())
a=sorted(a)
for _ in range(q):
    b,c=map(int,input().split())
    for i in range(n):
        if a[i]==b:
            a[i]=c
        elif a[i] > b:
            break
        else:
            pass    
    print(sum(a))