n=int(input())
a=sorted(list(map(int,input().split())))
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    if b not in a:
        pass
    else:
        a[a.index(b):a.index(b)+a.count(b)]=[c for i in range(a.count(b))]
    print(sum(a))